Flatpickr calendar show wrong default date

Pet picture Pet · Jan 25, 2018 · Viewed 7.6k times · Source

I have facetwp installed in wordpress and after the search was made, the search widget doesn't show the correct date as per selected before search

how to override this display issue (selected date) by javascript?

To view this problem in action : https://www.sweetpictures.com.my/product-category/photographers/?fwp_photo=2018-01-31%2C2018-01-31%2C1&fwp_productcategory=ampang&fwp_expertise=wedding-reception

Supposed the calendar picker selected date was 31st jan 2018 but instead it shows Aug 20th 2018

Kind help and assistance appreciated

Answer

aroy314 picture aroy314 · Jan 31, 2018

Use the documentation of Flatpickr to set the default date to the one you want : https://chmln.github.io/flatpickr/examples/#supplying-dates-for-flatpickr

That way you can add the following parameters to you flatpickr instance :

//example with jQuery
$('#your-date-element').flatpickr({
   minDate: 'today',
   dateFormat: 'd/m/Y'
})

If this is not working, try setting the input to the good date with the onReady function in the flatpickr instance :

//example with jQuery
$('#your-date-element').flatpickr({
    minDate: 'today',
    dateFormat: 'd/m/Y',
    onReady: function (selectedDates, dateStr, instance) {
        $('#your-date-element input').val(
            instance.formatDate(new Date(), 'd/m/Y')
        )
    },
})