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).ready(function($)
{
//#input_[form_id]_[field_id]
//Get Date Field
var $dateField = $( "#input_16_6" );
var date = new Date($dateField.val());
//Get Weekday Time Dropdowns
var $mondayTimes = $( "#input_16_7" );
var $tuesdayTimes = $( "#input_16_8" );
var $wednesdayTimes = $( "#input_16_9" );
var $thursdayTimes = $( "#input_16_10" );
var $fridayTimes = $( "#input_16_11" );
//Store in array
var weekdayTimes = ['sunday',$mondayTimes,$tuesdayTimes,$wednesdayTimes,$thursdayTimes,$fridayTimes,'saturday'];
//Disable Weekends on date
$dateField
.datepicker({ gotoCurrent: true, prevText: '<', nextText: '>', showOn: 'both', beforeShowDay: jQuery.datepicker.noWeekends });
//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);
//"Fake" Conditional Logic
$dateField.on('change', function()
{
//Update our date
date = new Date($(this).val());
showDropdowns(date);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment