Last active
November 12, 2018 18:34
-
-
Save superpowered/5f518fd61bc71a2f2b0e88ffa1fc5fb4 to your computer and use it in GitHub Desktop.
Gravity Forms. Disable weekends - Allow time selection based on day.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Note that this does NOT validate server side. | |
jQuery(document).on('gform_post_render', function($) | |
{ | |
//#input_[form_id]_[field_id] | |
//Get Date Field Input | |
var $dateField = jQuery( "#input_16_6" ); | |
var date = new Date($dateField.val()); | |
//Get Weekday Time Dropdown fields | |
var $mondayTimes = jQuery( "#field_16_7" ); | |
var $tuesdayTimes = jQuery( "#field_16_8" ); | |
var $wednesdayTimes = jQuery( "#field_16_9" ); | |
var $thursdayTimes = jQuery( "#field_16_10" ); | |
var $fridayTimes = jQuery( "#field_16_11" ); | |
//Store in array | |
var weekdayTimes = ['sunday',$mondayTimes,$tuesdayTimes,$wednesdayTimes,$thursdayTimes,$fridayTimes,'saturday']; | |
//Disable Weekends on date | |
$dateField | |
.datepicker({ "beforeShowDay": jQuery.datepicker.noWeekends, "dateFormat":"mm/dd/yy"}); | |
//Hide all dropdowns other than one specified | |
function showDropdowns(index) | |
{ | |
for(var x = 1; x < weekdayTimes.length - 1; x++) | |
{ | |
weekdayTimes[x].hide(); | |
} | |
if(index && index !== 6) | |
weekdayTimes[index].show(); | |
} | |
//Hide all dropdowns by default | |
showDropdowns(date.getDay()); | |
//"Fake" Conditional Logic | |
$dateField.on('change', function() | |
{ | |
//Update our date | |
date = new Date(jQuery(this).val()); | |
showDropdowns(date.getDay()); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment