Validating input to verify the content being provided. To recap the steps in the video:
Action Validation: Contact Number
Add an action to validate the data typed in for new contacts:
- Open the Contacts stream,
- Go to the section Actions, and add a new action
- Give the action the following settings:
- Name: Validate Contact
- Display Name: Validate Contact
- Go to the section Action Validation
- Type in the following expression, to check that phone numbers typed in contain only numbers or spaces:
do ( if (!matches(_form.ContactNumber, "[0-9 ]+"), error("Invalid phone number") ) )
Raising an error in a validation expression - using the error() function will stop the action at that point. That is, the data in the form will not be saved, and any other tasks in the action (e.g. running task plans) will not go ahead.
- Go to the section Stream Item Action Rules
- Add a Stream Item Action Rule
- Add a Stream Action Item
- Name: Validate Contact
- Set Stream Item Action to Update
- Press Apply
- Tick Copy Values by Name
- Add a Stream Action Item
- Add a Stream Item Action Rule
- Go to the section Stream Item Action Rules
- Save all your changes to the action
- Drag the action on top of the Add button, and the Update button on the ContactManager dashboard.
That completes the configuration. It is useful to see what is going on behind the scenes - click on the Add button - in the configuration, you can see that by dragging the action on the button, you have set the Action for the button to Validate Contact.
Go into App Mode. Type in a new contact, and include an invalid character in the telephone number - for example, a letter. This should be trapped with an error. You can correct this, then save the new contact.
Action Validation: Contact Name
Next we'll add some additional validation to check that the contacts names have been set:
- Open the configuration form for the Action Validate Contact
- You can either open the stream configuration form for Contacts, and find the list of actions; or click on the Add or Update button, and from the button configuration form, follow the quick link to the action details
- Add a condition to the Action Validation to check that the FirstName and FamilyName are both set:
- Add following expression to the existing action validation, to check that both names are provided:
if ( (isEmpty(_form.FirstName) || isEmpty(_form.FamilyName) ), error("Please complete both names for the contact") )
Save the changes to your action and test the changes in App Mode
The final Action Validation will look like this:
do( // Validate the Contact Number if (!matches(_form.ContactNumber, "[0-9 ]+"), error("Invalid phone number") ), // Validate the Contact Names if ((isEmpty(_form.FirstName) || isEmpty(_form.FamilyName)), error("Please complete both names for the contact ") ) )