Add Required Fields
Last updated 16/12/2021
How to Add Required Fields to a Form
This documentation will explain how to add fields to a form that are required to have a value entered.
By writing a condition in JavaScript® you can choose to make a field mandatory to have a value according to your requirements. The condition can be as simple as:
true
to make the field required, orfalse
to make the field not required
Default
true
for the first fieldfalse
for all other fields
Example
You can write a condition using Five's API and specify that if the Field ID on the current form is empty or NULL
make the field with the condition true
.
(form.FieldID === '' || form.FieldID === NULL)
On an Employee form you may have the fields Email and Phone. By writing the conditon (form.Email === '' || form.FieldID === NULL)
in the Phone field, the result will be that if the Email field is empty or NULL
make the Phone field required.
Steps
- Select Forms in the menu.
- Select the required form record in the list.
- Click the Pages tab.
![Select the Form Record](/2.5/img/forms/form-fields/how-to-guides/required-if/select-form-record.png)
- Select the required page record.
![Select the Page Record](/2.5/img/forms/form-fields/how-to-guides/required-if/page-record.png)
- Click the Fields tab.
![Fields Tab](/2.5/img/forms/form-fields/how-to-guides/required-if/fields-tab.png)
- Select the required field record.
![Select the Field Record](/2.5/img/forms/form-fields/how-to-guides/required-if/field-record.png)
- Either click the Edit button in the form app bar or click in the Required If field.
![Edit the form](/2.5/img/forms/form-fields/how-to-guides/required-if/edit-button.png)
- Type your condition,
(form.Email === '' || form.FieldID === NULL)
, in the Required If field. - Click the Save button in the form app bar.
![Type Condition and Save the Form](/2.5/img/forms/form-fields/how-to-guides/required-if/required-if.png)
- Click both Save buttons in the stacked form app bars above the list.
![Save the Form](/2.5/img/forms/form-fields/how-to-guides/required-if/save-form.png)
A condition can be added to the Required If field on the creation of the form.
How This Will Look in Your End-User Application
A required form field will be marked with an asterisk in your end-user application to signify the field is required. A user trying to save a form without inputting data in a required field will be delivered a notification that the field requires a value before it can be saved.
In the end-user application the Phone field will be marked with an asterisk.
![Phone Field is Required](/2.5/img/forms/form-fields/how-to-guides/required-if/phone-required.png)
If a value is entered in the Email field, the Phone field will no longer be required.
![Phone Field is No Longer Required](/2.5/img/forms/form-fields/how-to-guides/required-if/phone-not-required.png)