Projects created with WebMaker 3.1.1 include a utility script function that can be used to easily restrict the available values for a date field.
This function is called hyf.calendar.setDateConstraint, and takes in three parameters, the id of the date field to constrain, whether you want to set a minimum or maximum value for the field, and how to determine the constraint value.
If you wanted to restrict a field to always be before the current date, then you would add an 'onload' page event to your page, using the Field Details tab in FromMaker. Set the action type to 'Custom Script', and then enter the following type of script fragment:
hyf.calendar.setDateConstraint('my_date_field', 'Maximum', 'Today');
You would need to replace my_date_field with the actual name of the date field you want to restrict. You should now find that the calendar does not allow the user to select any dates in the future, and if the user manually enters one, the validation process will detect this as an error.
Alternatively, if you want to restrict the value of a date field based on another field (eg for entering a from and to date range), then you could add an 'onchange' event definition to the base (from) field. In this case you would enter Custom Script for the form:
hyf.calendar.setDateConstraint('to_date_field', 'Minimum', 'from_date_field');
where to_date_field and from_date_field are the names of the two fields as appropriate. This will ensure that the value entered into the to_date_field is always after the date selected for the from_date_field. You will probably also want to add this script as an onload event, to make sure that the constraints get correctly initialised on page load.
It is also possible to combine these different types of constraint, eg to make sure that the from date is after today, and that the to date is after that.
This function is called hyf.calendar.setDateConstraint, and takes in three parameters, the id of the date field to constrain, whether you want to set a minimum or maximum value for the field, and how to determine the constraint value.
If you wanted to restrict a field to always be before the current date, then you would add an 'onload' page event to your page, using the Field Details tab in FromMaker. Set the action type to 'Custom Script', and then enter the following type of script fragment:
hyf.calendar.setDateConstraint('my_date_field', 'Maximum', 'Today');
You would need to replace my_date_field with the actual name of the date field you want to restrict. You should now find that the calendar does not allow the user to select any dates in the future, and if the user manually enters one, the validation process will detect this as an error.
Alternatively, if you want to restrict the value of a date field based on another field (eg for entering a from and to date range), then you could add an 'onchange' event definition to the base (from) field. In this case you would enter Custom Script for the form:
hyf.calendar.setDateConstraint('to_date_field', 'Minimum', 'from_date_field');
where to_date_field and from_date_field are the names of the two fields as appropriate. This will ensure that the value entered into the to_date_field is always after the date selected for the from_date_field. You will probably also want to add this script as an onload event, to make sure that the constraints get correctly initialised on page load.
It is also possible to combine these different types of constraint, eg to make sure that the from date is after today, and that the to date is after that.