Min And Max Date With Date Format In Elementor Form Not Working

Question

I am using Min and Max date in the Elementor Form. The Min and Max date are working fine but When I add the Date Format, the Min & Max date is not working and Date Format is working.

My Min & Max Date Code Added In function.php:

add_action( 'wp_footer', function() {
?>
<script type="text/javascript">
    jQuery( window ).load( function( $ ){
        var limitFlatPicker;
        var afterTwoDays;
        var afterEightDays;
        limitFlatPicker = limitFlatPicker || {};
        limitFlatPicker = {
            defaultSettings: {
                selector: '.flatpickr-input',
                minDate: true,
                maxDate: true,
            },
            settings: {},
            init: function( options ) {
                this.settings = jQuery.extend( this.defaultSettings, options );
                if ( this.settings.minDate || this.settings.maxDate ) {
                    this.waitForFlatpicker( this.callback );
                }
            },
            waitForFlatpicker: function( callback ) {
                if ( typeof window.flatpickr !== 'function' ) {
                    setTimeout( function() { limitFlatPicker.waitForFlatpicker( callback ) }, 100 );
                }
                callback();
            },
            modifyPicker: function( picker, settings ) {
                flatpickr( picker ).set( settings );
            },
            callback: function() {
                var self;
                self = limitFlatPicker;
                jQuery( self.settings.selector ).each( function() {
                    var picker;
                    picker = jQuery( this )[0],
                    pickerSettings = {};

                    if ( self.settings.minDate ) {
                        pickerSettings['minDate'] = self.settings.minDate;
                    }
                    if ( self.settings.maxDate ) {
                        pickerSettings['maxDate'] = self.settings.maxDate;
                    }
                    self.modifyPicker( picker, pickerSettings );
                } );
            }
        }

            limitFlatPicker.init( {
                minDate: new Date(),
                selector: '#form-field-form_field_date',
            });         

    } );
</script>

<?php
},11);

But When I add the Date Format Code In functions.php, the Min & Max date is not working but Date Format is working:

add_action('wp_footer', function () {
       ?>
      <script>
      jQuery( document ).ready( function( $ ){
            setTimeout( function(){
                  $('.flatpickr-input').each(function(){ flatpickr( $(this)[0] ).set('dateFormat', 'd/m/Y');});
            }, 1000 );
      });
      </script>
      <?php
},13);

So, I want to add the Min and Max date with the Date Format.

I also tried to add this in the above code but it is not working:

 limitFlatPicker.init( {
            minDate: new Date(),
            dateFormat: 'd/m/Y',
            selector: '#form-field-form_field_date',
        }); 

Any help is much apprecaited.

0
, Rahul Kumar 7 months 0 Answers 149 views 0

Leave an answer