Validation Rules
Validation rules decide which values a field accepts. Cnidarity checks them when a record is saved and refuses the save if any value fails. This page covers the rules for each type, conditional rulesets, and adding rules after records exist.
Built-in Validation
Set rules in the Validation Rules section of the field's edit page. Check a rule to turn it on, and fill in its value if it has one. Some rules are added automatically for a type and can't be unchecked, such as Email Format on an Email field.
Rules available by type:
- Short Text, Long Text: Required, Numeric Only, Minimum Length/Value, Maximum Length/Value, Unique Value, Alphabetic Only, Alphanumeric, Dashes & Underscores, Custom Pattern (Regex).
- Number: Required, Numeric Only, Minimum Length/Value, Maximum Length/Value, Decimal Precision, Unique Value.
- Date/Time: Required, Date Format, Minimum Length/Value and Maximum Length/Value as earliest and latest dates.
- Email: Required, Email Format, Unique Value.
- URL: Required, URL Format.
- Multiple Choice, Image, Media Slider, 3D Model: Required.
- Yes/No: none.
For text, Minimum and Maximum are character counts. For Number, they're values. Unique Value means no two records of the data model can have the same value.
Adding rules when records exist. On a field with values, Cnidarity checks existing values against the new rules ("Checking validation impact...").
- Adding Required shows how many records are empty. Nothing changes; those records must be filled in the next time they're edited.
- Tightening any other rule shows how many values fail and offers Delete these values or Keep values as-is. Kept values stay until someone edits the record, which then has to pass.
- Tightening Decimal Precision rounds existing values.
Conditional Validation
Below the standard rules, Conditional Validation Rules let you apply rules that depend on other fields. Click Add Conditional Ruleset. A field can have up to 5 rulesets, on every tier.
Each ruleset has two parts:
- When these conditions are met: optional conditions on other fields of the same data model. Without conditions, the ruleset always applies.
- This field: one or more rules for this field. Each Rule can compare against a fixed Value or, with Compare Against, another field's value.
Rules available in a ruleset:
- Is required
- Must be greater than, Must be greater than or equal to, Must be less than, Must be less than or equal to (Short Text, Number, Multiple Choice)
- Must be before, Must be after (Date/Time)
- Number of selections must equal, be less than, be greater than, and the or-equal-to forms (Multiple Choice)
- Must be the same as, Must be different from
For example: Total Biomass Is required when Individuals Caught is Greater Than 0. Or: End Date Must be after Start Date.
Required can be set in only one of the two sections. If Required is checked in the standard rules, Is required isn't offered in rulesets. If a ruleset uses Is required, the standard Required shows "Unavailable - conditional requirements are active."
Display rule or conditional Is required? Both make a field matter only in some cases, but they treat data differently:
- A display rule hides the field while its conditions are false, and saving the record deletes any value it had.
- A ruleset with Is required keeps the field on the form at all times and only requires it while the conditions are true. Values entered when the conditions are false are kept.
Use a display rule when the question doesn't apply in other cases. Use conditional Is required when the answer is optional in general but needed in some cases, such as Total Biomass, which is worth recording whenever it's known but required once fish were caught.
Conditional rulesets aren't available for a relationship's Additional Fields.
conditional-validation-rulesetRuleset 1 under Conditional Validation Rules, with two Habitat Type conditions joined by OR under When these conditions are met, and This field: Rule set to Is required
One complete ruleset: two Habitat Type conditions joined by OR, then the rule they trigger under This field.
Condition Builder
Ruleset conditions work like display rule conditions. Pick a Field, a Condition, and a Value. Combine conditions with AND or OR, and use groups for mixed logic, up to two levels deep with 4 conditions per group. The conditions are listed on Display Rules. Rulesets use "Has a value" and "Is empty" where display rules use Is Not Empty and Is Empty.
Custom Rule Values
Set ranges from what is physically possible, so typing mistakes are caught. A Count of 0 to 199 rejects negative numbers and an extra digit. A Water Temperature (°C) of -5 to 40 catches readings typed in Fahrenheit.
On Number fields, Minimum Length/Value, Maximum Length/Value, and Decimal Precision also set the limits of the input itself, so the browser blocks a value outside them before the form is submitted. Without Decimal Precision, a Number accepts whole numbers only (Field Types Reference).
Validation Feedback
Validation runs on the server when someone clicks save. If a value fails, the record isn't saved, the form stays filled in, and an error message appears under each field that failed. Fix the values and save again.
The browser blocks a few values before the form is submitted: Number values outside the Minimum or Maximum or with more decimal places than Decimal Precision allows, and Email and URL values in the wrong format. The server checks every rule, including Required, when the form is submitted.
Imports check every rule except Required. Rows that fail another rule are listed with the reason and aren't imported. Rows with an empty required field are imported, and the review step says how many. Those records must be completed the next time someone edits them.
validation-error-on-formA record form after a failed save, with an error message under the Collection Date field saying it is required
After a failed save, each error appears under its field.

