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.
- Summary
Adds validation to widgets. Available validations:
Presence: By default all widgets are required, unless specified in the config. Example:
- {label: "Subtitle", name: "subtitle", widget: "string", required: false}
Pattern: Field configuration can specify a regex pattern with the appropriate error message. Example:
- {label: "Title", name: "title", widget: "string", pattern: [".{10,}", "Should have more than 10 characters"] }
The widget control can optionally implement an
isValid
method to perform custom validations, in addition to presence and pattern. TheisValid
method will be automatically called, and it can return either a boolean value, an object with an error message or a promise. Examples:Boolean
No errors:
Existing error:
Object with
error
(Useful for returning custom error messages)Existing error:
Promise
You can also return a promise from isValid. While the promise is pending, the widget will be marked as in error. When the promise resolves, the error is automatically cleared.
Note: Do not create a promise inside isValid - isValid is called right before trying to persist. This means that even if a previous promise was already resolved, when the user hits 'save',
isValid
will be called again - if it returns a new Promise it will be immediately marked as in error until the new promise resolves.- Test plan
- Description for the changelog
Added support for validations.
- A picture of a cute animal (not mandatory but encouraged)