Conditional validation for your mobile forms
If you have a form that has some fields in it that only need to be filled out if another field meets a certain condition, then you can do this in XForms using the conditional validation attribute.
XF
XForms team
Aug 7, 2023

IF {field_1} = “value x”, THEN {field_2} “IsRequired”
The above is a representation of a conditional validation statement. In simple terms, this feature is used whenever you have a form that has some fields in it that only need to be filled out if another field meets a certain condition. For example, maybe you have a checkbox field, and if its checked, then the user is required to fill out some other areas of the form. However, if its unchecked, the user can skip those other areas.
You can do this with any field type, not just checkboxes. For example, you could create a validation where if a text field (or numeric field) has a value of X, then require the user to fill out the others fields, otherwise don’t require those fields.
Here’s an example of what that looks like in the mobile app. In the example below, if you check that checkbox on the left side of the screen (were any issues observed at any of the properties in the neighborhood), then the user will not be able to submit the form until they select a value from the “properties with issues” multiselect listbox or fills out the table below it. And if the user leaves that checkbox blank, then the user will not have to fill out the other fields mentioned.
Syntax and attributes of this feature
The syntax of this expression is as follows:
“requiredWhen”: “field_id~operator~value“
The “requiredWhen” setting is a 2 or 3-part statement in the following format:
“field_id~operator” or “field_id~operator~value”
field_id: ID of the field to compare with
value: the value to compare the field (above) with. This could be a single number or string, or a list of values (optional)
Operators:
You can compare against a specific value or range of values using the following operators:
- checked : checks if the checkbox with specified ID is checked.
- unchecked : checks if the checkbox with specified ID is unchecked.
- = : checks if the value of the field is equal to one of the items in the value list. Example: cityField~=~’Boston’,’Chicago’
- <> : checks if the value is not equal to the value in the field
- < : for numeric fields…checks to see if the value is less than the value in the field
- > : for numeric fields…checks to see if the value is greater than the value in the field
- >= : for numeric fields…checks to see if the value is less than or equal to the value in the field
- <= : for numeric fields…checks to see if the value is greater than or equal to the value in the field
Here’s an example:
“requiredWhen”: “issues_yn~checked”
In the example above, there is a field (issues_yn) . The validation control is checking to see if that checkbox field is checked.
All of this may seem a bit complicated, and yea, its more complicated-looking that we’d like. A future release will make this easier to use. For now, suffice it to say that if you have some conditional validations you need on your form, it can be done.
Want to give XForms a try?
Click/tap the button below.
TRY XFORMS
Wanna give it a try, risk-free?
Build a form, capture a record offline and see it land in your dashboard.
XF
WRITTEN BY
XForms team
Keep reading
XForms Mobile
Sep 5, 2025
Tracking waste from cradle to grave using smartphones + AI
How do you ensure that the decarbonization end-product you are paying top dollar for originated from actual waste, and not virgin material?

XForms Mobile
Mar 2, 2025
Photos in table rows
Now you can take a photo within a table grid row, enabling you to take pictures of something specific and relevant to the information in that row of your table.

XForms Mobile
Jan 6, 2025
Photo metadata improvements
Photo metadata is now captured at the photo level instead of at the form level. This enables viewing of the geolocation of each photo taken, which could differ for each photo captured on the same form.
NEWSLETTER
Get new posts in your inbox
Product updates, field-tested how-tos and customer stories from XForms Mobile, Cx and XDocs.
New blog newsletter signup
One email when we publish. Unsubscribe anytime. or request a demo →

