all
Strickland provides an all
validator. The all
validator operates over an array and it will only return a valid result if all validators in the array are valid. But all
has a significant difference from every
: all
will always execute all validators, regardless of previous results. You can use all
if all validators are safe to execute and you need to know all validator results, even if some are invalid.
Parameters
The first parameter to the all
validator factory is the array of validators. Validator props can also be supplied either as an object or as a function that accepts context and returns a validator props object.
Result Properties
all
: The array of validation results produced during validation
The all
validator adds an all
property to the validation result with the validation results of all validators that were validated in the array of validators. The validation result property is named all
to match the name of the validator (this is a common pattern in Strickland).
Usage
There are a few notable characteristics of this result:
The properties from all executed validators are added to the top-level result
The
required
validator added therequired: true
property to the resultThe
minLength
validator added theminLength: 5
property to the resultThe
maxLength
validator added themaxLength: 10
property to the result
Property collisions are resolved using last-in-wins
In this example, the
message
from themaxLength
validator replaced the messages provided by therequired
andminLength
validatorsThis behavior is consistent and predictable with Strickland, but limits how top-level result properties can be used with the
all
validator
All validators are executed, even after the result is known to be invalid
The top-level
isValid
prop on the result reflects the overall validation result
Last updated