gravity forms date field tweak - no weekends and past dates

Remove weekends and past dates from Gravity Forms date field

Client needed to have weekends removed for the date field of the booking form on Gravity Forms.

Add this to your child’s theme function.php or snippet plugin.
Make sure you change the ID of the field. In the example below input_1_4 refers to form ID 1 and field ID 4.

add_action( 'wp_footer', function() {
    ?>
    <script>
    jQuery(document).ready(function($){

        setTimeout(function(){

           $('#input_1_4').datepicker(
				'option',
				{
					beforeShowDay: function(date) {
						var day = date.getDay();
						var today = new Date();
						today.setHours(0,0,0,0);

						if (date < today) return [false];
						if (day === 0 || day === 6) return [false];

						return [true];
					},
					minDate: 0
				}
			);

        }, 300);

    });
    </script>
    <?php
});

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *