Skip to content

Instantly share code, notes, and snippets.

@superpowered
Last active November 12, 2018 18:34
Show Gist options
  • Save superpowered/5f518fd61bc71a2f2b0e88ffa1fc5fb4 to your computer and use it in GitHub Desktop.
Save superpowered/5f518fd61bc71a2f2b0e88ffa1fc5fb4 to your computer and use it in GitHub Desktop.
Gravity Forms. Disable weekends - Allow time selection based on day.
//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