How do I use Validation Logic with my Form Fields?

Modified on Thu, 22 Feb 2024 at 12:40 PM

By default, all fields on a form are required before the submission can be submitted. If you would like to make some fields optional or add logic to make them conditionally required, you can use the Validation Logic formula field. 

The validation logic should be used when the field is only required under certain circumstances or the field will only accept a certain data. If you would simply like to make a field optional at all times, you can toggle off the Required property for that field.

There are two helper functions that will be necessary when adding your conditional logic. The isRequired(value) helper function will tell the form when the field is required. Please note: the word "value" is used to let a component refer to itself. 



The other commonly used helper function will tell the form when the field optional. This is helpful for information that is nice to have but shouldn't stop a submission if it isn't present. Note: this helper function does not need to reference the word "value" or any ID. 


There are a number of other helper functions as well as other Javascript that could be useful to create custom Validation Logic formulas. 


withinRange(value, min, max) 

equals(expected, actual)

notEquals(expected, actual)

isGreaterThan(num1, num2) 

isGreaterThanOrEqualTo(num1, num2)

isLessThan(num1, num2)

isLessThanOrEqualTo(num1, num2)

and(val1, val2)

or(val1, val2)

includes(list, value)

toCurrency(number) => string

fromCurrency(string) => number

Best Practices with Custom Validation
We recommend adding a tooltip or hint to fields with custom validation to help the user understand what they need to provide in order to submit. Another option would be to include a text field that uses an opposite display logic function so it appears like an error message when the validation logic fails.

Common Examples

When the field is conditionally required depending on an option selected:

Checkbox or Dropdown(multi-option select) with Options:

componentID.includes('Option 1') ? isRequired(value) : isOptional()

Radio or Dropdown(single option select only) with Options:

componentID === 'Option 1' ? isRequired(value) : isOptional()

When the field should only accept a certain format:

An Approver Email field that needs to include the organization domain and not be the submitter's email:

approverEmail.endswith('') && approverEmail.toLowerCase() !== submittedByEmail

When the field should only accept a certain number of characters:

Employee Number field should only accept 6 characters:

employeeNumber.length === 6

When the field is conditionally required depending on the step:

This field is editable on both the start step and the HR step, but needs to be completed on the HR Step.

currentStep() === 'hrStep' ? isRequired() : isOptional()

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article