Mandatory fields in forms
In online forms, it is common to use mandatory fields that must be filled in before the form can be submitted.
You can also provide this functionality in todo4teams - in any way you like.
- Switch to the "Forms" tab
- Select the form for which you want to set up mandatory fields.
- Select the "Scripts" tab.
- Switch to the "Submit Action" tab.
This script action is executed as soon as the user uses this form and tries to submit the ticket.
if(name.length()==0){
helper.errorMessage("Please enter a name!");
result="error";
}
The script now determines the input in the "Name" field. If nothing has been entered there (i.e. name.length()==0), an error message is displayed using the helper.errorMessage() method and the assignment result="error" prevents the ticket from being sent.
The user then has the option of completing their input and trying again.
You can go a step further by linking several fields with dependencies:
For example, if you offer the fields "Postal code" and "Location", you could require that the postal code must always be specified along with the location, but that both can be left blank.
A corresponding script could then look like this:
var zipcode = form.getValueByFieldName("ZipCode");
if(city.length()>0 && zipcode.length()==0){
helper.errorMessage("Please enter the zip code!");
result="error";
} else if(city.length()==0 && zipcode.length()>0){
helper.errorMessage("Please enter the city!");
result="error";
}