Disabling the dates from the past from datepicker

Hi, I’m trying to restrict datepicker so that choosing dates from the past would not be possible, but I’m not sure how… Thanks

Hey Dimitrije,

what date picker are we talking about? In the form element? If so please try the bricks/element/form/datepicker_options hook:

add_filter( 'bricks/element/form/datepicker_options', function( $options, $element ) {
    if ( $element->id === 'yvjesh' ) { // your form element's ID here
        $options['minDate'] = 'today';
    }

    return $options;
}, 10, 2 );

Best,

André

Hey, thanks for responding!
Sorry, but where should I insert the code, I’m still a beginner in using bricks :sweat_smile:
thanks!

Hey Dimitrije,

no problem. :slight_smile:

If you’re using the Bricks child theme you can put this code into the child theme’s functions.php file.

Alternatively you could use a code snippet plugin (WPCodeBox, Advanced Scripts, Code Snippets etc.) and create a PHP snippet in one of those plugins.

As commented in my code snippet make sure to replace the form ID (yvjesh) with your actual form element’s ID.

Best,

André