Nested constraints, array and struct shorthand syntax, and validator aliases #60
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR has three main components:
Nested Constraints
Nested structs can be validated using the
constraintsornestedConstraintsvalidator.Using the
nestedConstraintsvalidator requires the item it is used on be a struct. Otherwise a validation error will occur.When using
nestedConstraintsthe field name of the errors will be the dot-delimited path of the target.The field name change also applies to
itemsorarrayItemvalidators.The field name changes will allow you to match the validation errors to your fields in your forms.
While cbvalidation can nest constraints down as far as you'd like to go, remember that each nested level increases complexity.
Array and Struct Shorthand Syntax
To make defining array item and nested constraint validators easier, you can use a shorthand on the field name, like so:
Dot-delimited strings represent nested structs while the asterisk (
*) represents an array of items. This shorthand syntax is expanded to the equivalent syntax above before validating. Use whichever you prefer.Validator Aliases
A few of the built-in validators now have an alias in addition to the longform validator name:
{ "items": "arrayItem", "constraints": "nestedConstraints" }Co-authored by @garciadev