Checks
What an answer must be, compared with other answers, numbers or dates.
A check
{
key: "female_staff",
type: "number",
label,
checks: [{ atMost: "total_staff" }],
}
The words are equals, atMost, atLeast, lessThan and moreThan. A rule that involves two fields goes on the one whose error should show.
Try it in the tutorial: Checks between fields.
What to compare with
| Target | Example |
|---|---|
| another field | { atMost: "total_staff" } |
| a number | { atLeast: 18 } |
| yes or no | { equals: true } |
| today | { atLeast: "today" } |
| a span from today | { atLeast: { fromToday: { years: 1 } } } |
| a sum | { equals: { sum: ["male", "female"] } } |
| a property of the pick | { atMost: { field: "room_type", property: "max_size" } } |
Dates
On dates the words read as before and after: atLeast is on or after, moreThan is after, atMost is on or before, lessThan is before. A span takes years, months and days.
{ key: "opening", type: "date", label, checks: [{ atLeast: "today" }] }
Try it in the tutorial: Checks against today.
Messages
The message is written for you, in every language, from the other field's label: Must be at most staff. message replaces it.
A check waits while either side is blank, and Fill step in the debugger produces answers that pass it.
Only sometimes
when limits a check to some answers, written like a field's when:
checks: [{ atLeast: 2, when: { field: "kind", equals: "BAR" } }]
Any rule
For a rule none of the words cover, valid is a function of the section's answers. Give it a message.
checks: [{ valid: answers => !answers.terrace || Number(answers.outdoor_seats) > 0, message: "Add the terrace's seats" }]
Rows
On a list, rows counts the rows that match a condition, and the words compare that count. Without a word, at least one row must match.
checks: [{
rows: { field: "role", equals: "MANAGER" },
equals: 1,
message: "Name one manager",
}]
Fields inside a list's rows take checks too, compared with the other answers in the same row.