JQuery No Weekends Gravity Forms

I used the gform_post_render function in Gravity Forms to create a custom datepicker parameter using the minDate option to select 1 day in advance:

http://www.gravityhelp.com/documentation/page/Gform_post_render

Is there a way I can rule out weekends? I just want the user to be able to select the days of the week with one day in advance. I tried using beforeShowDay: $.datepicker.noWeekends , but it seems to conflict with minDate

Here is my form: http://www.discountdumpsters.com/shop/30-yard-dumpster/

And here is my code:

 <script type="text/javascript"> jQuery(document).bind('gform_post_render', function(){ // destroy default Gravity Form datepicker jQuery("#input_1_1").datepicker('destroy'); // create new custom datepicker jQuery("#input_1_1").datepicker({ defaultDate: '+1d', minDate: '+1d', gotoCurrent: true, prevText: '', showOn: 'both', buttonImage: 'http://www.discountdumpsters.com/wp-content/plugins/gravityforms/images/calendar.png', buttonImageOnly: true }); }); </script> 

Any help would be appreciated ... thanks!

+4
source share
3 answers

I realized that I never answered this question. Here is the last code that worked for me:

 jQuery(document).bind('gform_post_render', function(){ // destroy default Gravity Form datepicker jQuery("#input_1_1").datepicker('destroy'); // create new custom datepicker var oneWorkingDays = new Date(); var adjustments = [0, 1, 1, 1, 1, 1, 0]; // Offsets by day of the week oneWorkingDays.setDate(oneWorkingDays.getDate() + 1 + adjustments[oneWorkingDays.getDay()]); jQuery("#input_1_1").datepicker({ beforeShowDay: jQuery.datepicker.noWeekends, minDate: '+1d', gotoCurrent: true, prevText: '', showOn: 'both', buttonImage: '/wp-content/plugins/gravityforms/images/calendar.png', buttonImageOnly: true }); }); 
0
source

I think you should queue your script in the footer and not in the head

0
source

I actually used your code in an external js file, and it works even with the noweekends declaration

 jQuery(document).bind('gform_post_render', function(){ // destroy default Gravity Form datepicker jQuery(".datepicker").datepicker('destroy'); // create new custom datepicker jQuery(".datepicker").datepicker({ defaultDate: '+1d', minDate: '+1d', gotoCurrent: true, prevText: '', showOn: 'both', buttonImage: '/wp-content/themes/teloaggiustoio/images/calendar_icon.png', buttonImageOnly: true, beforeShowDay: $.datepicker.noWeekends }); }); 
0
source

Source: https://habr.com/ru/post/1441342/


All Articles