Hey! I’m using a date picker for a couple of fields on my forms, and I set up a date range for them using:
function setDateRange(w,x,y,z){
gform.addFilter( 'gform_datepicker_options_pre_init', function( optionsObj, formId, fieldId ) {
if ( formId == w && fieldId == x ) {
var ranges = [
{ start: new Date(y), end: new Date(z) }
];
optionsObj.beforeShowDay = function(date) {
for ( var i=0; i<ranges.length; i++ ) {
if ( date >= ranges[i].start && date <= ranges[i].end ) return [true, ''];
}
return [false, ''];
};
optionsObj.minDate = ranges[0].start;
optionsObj.maxDate = ranges[ranges.length -1].end;
}
return optionsObj;
});
}
setDateRange(1, 3, '03/31/1956', '01/01/2020'); // form id, field id, start date, end date
setDateRange(2, 9, '03/31/1956', '01/01/2020');
This is working as far as the dates are unavailable outside of this range on the calendar that pops up, BUT if the user types in a date outside of this range, the form will allow them submit without throwing an error. What should I be doing to validate this field to make sure only dates within the given range are submitted?
Thanks in advance!