Pet
Pet

Reputation: 71

Flatpickr calendar show wrong default date

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

Upvotes: 1

Views: 10796

Answers (1)

aroy314
aroy314

Reputation: 51

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')
        )
    },
})

Upvotes: 2

Related Questions