An advantage to software forms is that developers can add dynamic behavior. This article covers how to make a form field required based on the answer of another field.
This article assumes that the reader is already familiar with the Kinetic Request console and specifically the Form Builder.
This can be very useful tool for form developers. Based on a user's input you may want to display fields to get more information. Is the information required for the successful completion of the request? If so add validation to the field.
This leaves a form developer in a little bind, because not all users may need to fill out this required field. It is only required based on the answer of another question.
Here comes Kinetic Data to save the day. The form developer has tools to make a field required based on the condition of another field.
A simple example of how this could be useful to a form developer. A request asks the question "Will you need a new laptop?". Based on the answer to that question the user must provide a department charge number.
This example will only have those two questions. In a production setting there would be many other questions for the user to fill out.
- Add a Radio Button field with the values Yes and No.
- Add a Text field to gather the department charge number.
- With the text field selected click the Validation dropdown and select the Conditional radio option the the right or Required.
- The Condition field is required. Add an expression that will evaluate to true or false. (If true the field will become required)
- A Message to display to the user in optional. (If omitted a default message is provided)
If the user selects "No" to the question then the Department Charge Number field is not required.
If the user selects "Yes" then a red asterisk becomes visible to the right of the Department Change Number field.
If a user attempts to submit the form without the required field being valid then a alert message is displayed to them.