pixelcrash
pixelcrash

Reputation: 31

WP Forms + Flatpickr can not disable Dates

I have a date select field using WPForms and need to take out some dates. I already disabled all Sundays via the WPForm Setups, but I need to remove a specific date.

I am using this function - the minDate and maxDate work perfectly fine. Why can't I manage the disable thing?

<script>
  var form2 = document.getElementById('wpforms-form-3375');
  if(form2 != null){
        
   window.wpforms_datepicker = {
     disableMobile: true,
     disable: ["2023-11-09", "2023-12-02", new Date('December 1, 2023')],
     minDate: new Date('October 30, 2023'),
     maxDate: new Date('December 2, 2023') 
    }
}
</script>

<?php } ?>
<?php add_action( 'wpforms_wp_footer_end', 'form2Limits', 10 ); ?>

I tried using disable: ["2023-11-09", "2023-12-02", new Date('December 1, 2023')], no result

Upvotes: 0

Views: 495

Answers (1)

Crezzur
Crezzur

Reputation: 1479

Your code should work correctly

Flatpickr documentation: https://flatpickr.js.org/examples/#disabling-specific-dates

Snippet Example:

const start_date = flatpickr("#start_date", {
  dateFormat: 'Y-m-d',
  disable: ["2023-08-21", new Date()],
  //minDate: new Date('October 30, 2023'),
  //maxDate: new Date('December 2, 2023') 
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/flatpickr/4.6.13/flatpickr.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/flatpickr/4.6.13/flatpickr.min.js"></script>

<input type="text" id="start_date" name="start_date">

Upvotes: 0

Related Questions