Custom Validation
RapidForm allows you to implement advanced validation logic using JSONata expressions, enabling you to enforce complex business rules that go beyond basic "required" conditions. This step comes after you have added the neccessary fields in your RapidForm.
Enabling Custom Validation
Custom validation is applied at the form level and is executed on the data entered by the user across multiple fields. Toggle the Custom Validation option to enable this feature.
Configuring Custom Validation
Custom validation once toggled would look like :
Validation Configuration Options
1. Example Input Data (JSON)
- Provide sample JSON data to simulate and test your validation logic.
- Example:json
{ "projects": [ { "value": "1" }, { "value": "2" }, { "value": "3" } ] }
2. Validation Expression (JSONata)
- Write a JSONata expression that evaluates the input data.
- Expected Output:
- An array of error objects with:
- field: The field to which the error message applies.
- message: The error message to display.
- Or
undefined
if no errors are found.
- An array of error objects with:
- Example Expression:jsonata
($exists(projects) and $count(projects) >= 5) ? undefined : [{ "field": "projects", "message": "Select at least 5 projects" }]
- Explanation:
$exists(projects)
checks if theprojects
field exists.$count(projects)
counts the number of items in theprojects
array.- If there are at least 5 items, the validation passes (returns
undefined
). - Otherwise, it returns an error targeting the
projects
field.
3. Output
View the results of your validation expression applied to the example input data.
For the above example, the output would look like:
json[ { "field": "projects", "message": "Select at least 5 projects" } ]
Custom validation in RapidForm is a powerful feature that allows you to enforce precise business rules and ensure data accuracy before submission. By leveraging JSONata expressions, you can create dynamic, field-level validation that goes beyond basic requirements, enabling:
- Consistency: Validate inputs against your specific criteria to ensure clean, standardized data.
- Flexibility: Handle complex scenarios like interdependent fields or calculated requirements.
- User Guidance: Provide clear and actionable error messages to improve user experience and minimize mistakes.
By integrating custom validation into your RapidForm workflows, you enhance the reliability and usability of your forms, ensuring they meet both user and business requirements effectively. Let RapidForm handle the complexity so you can focus on delivering seamless integrations.