• Resolved martiv97

    (@martiv97)


    Hello there,
    I would like to ask you for a solution to this matter.
    I have 2 datepicker fields – one for arrival and second for departure. It is working now of course but its not connected. When I choose 6th Dec on arrival I can still choose date before arrival on departure field which does not really make sense. Is there any solution to this so I can only choose date equal or after 6th Dec?
    Thank you!

    EDIT: I have found this example using flatpickr but I have no idea how to implement this. I do have PRO version.
    https://formvalidation.io/guide/examples/using-flatpickr-for-start-and-end-dates/

    • This topic was modified 3 years, 6 months ago by martiv97.
    • This topic was modified 3 years, 6 months ago by martiv97.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi @martiv97,

    You can add the following code in the advanced date configuration section of the first date field (arrival field) –

    {
    onChange: function(selectedDates, dateStr) {
           var date = selectedDates[0];
    
           date.setDate(date.getDate());
    
           flatpickr('.endDate', {
            minDate: date,
    });
        }
    }

    Also, in the second date field (departure field) add the class endDate as the Element class in that field.

    That should allow you to only choose the date in the departure field after or equal to the arrival date.

    I hope this is what you are looking for.

    Thank you.

    Thread Starter martiv97

    (@martiv97)

    Excellent! Thank you it is working. But is it possible to change format to dd/mm/yyyy instead of yyyy/mm/dd? My departure field changed its format after that.

    • This reply was modified 3 years, 6 months ago by martiv97.
    • This reply was modified 3 years, 6 months ago by martiv97.

    Hi @martiv97,

    Glad to hear that the code is working.

    You can change the date format of the departure field by adding the date format (dateFormat: “d/m/Y”) directly in the code.

    This is the updated code –

    {
    onChange: function(selectedDates, dateStr) {
           var date = selectedDates[0];
    
           date.setDate(date.getDate());
    
           flatpickr('.endDate', {
            minDate: date,
            dateFormat: "d/m/Y",
    });
        }
    }

    Thank you!

    Thread Starter martiv97

    (@martiv97)

    You’re the legend. Thank you!

    Hi @martiv97,

    I am happy to help!

    We would very much appreciate it if you could spare a few minutes to share your experience and provide us with a review if you haven’t done it already.

    This feedback helps us improve our ability to provide you with the best possible support.

    To write a review, please visit here: https://ww.wp.xz.cn/support/plugin/fluentform/reviews/#new-post

    Thank you!

    Thread Starter martiv97

    (@martiv97)

    Sure you got it! The least I can do.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘datepicker 2 fields’ is closed to new replies.