• Resolved jana90

    (@jana90)


    Hello,

    I am using Ninja Forms for a contact form and am using the datepicker field. I need to restrict past dates. Can anyone help me how to do that?

    I googled this a lot and for someone this code worked but I don’t seem to get it working, can anyone help?

    function nf_datepicker_modify_script( $args ){
    //for a list of arguments which can be used here, see the options here https://api.jqueryui.com/datepicker/

    $args[‘minDate’] = 0
    return $args;
    }

    add_filter( ‘ninja_forms_forms_display_datepicker_args’
    ,’nf_datepicker_modify_script’ );

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi,

    I wrote a small plugin to config the ninja forms datapicker.

    var customDatePicker = Marionette.Object.extend( {
    initialize: function() {

    this.listenTo( Backbone.Radio.channel( ‘flatpickr’ ), ‘init’, this.modifyDatepicker );
    },

    modifyDatepicker: function( dateObject, fieldModel ) {

    dateObject.set(“minDate”, …);
    dateObject.set(“maxDate”, …);
    dateObject._initialDate = …;
    dateObject.set(“showMonths”, 1);
    }
    });

    jQuery( document ).ready( function( $ ) {
    new customDatePicker();
    } );

    Maybe this will resolve your problem

    Thread Starter jana90

    (@jana90)

    @martenw thank you so much for helping! I copied that code and added new date()); to the minDate value but it’s not doing anything for the datepicker ??

    Did you add the code as a plugin?
    If no
    Create a PHP file index.php with the code
    add_filter( ‘ninja_forms_enqueue_scripts’, ‘nf_datepicker_options’ );
    function nf_datepicker_options() {
    wp_enqueue_script( ‘nf_datepicker_options’, plugin_dir_url( __FILE__ ) . ‘custom-datepicker.js’, array( ‘jquery’ ), false, true );
    }

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Restrict past dates in ninja forms datepicker’ is closed to new replies.