-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support reporting top-level form validation errors
When we call `form.validate()` and the validation fails, the raised exception is a `deform.ValidationFailure`. This object has an `error` attribute which represents the underlying validation error object for the entire form. Previously, if the validation failure were a result of top-level validation errors (such as the fact that an unactivated user is trying to log in), this error would be lost, because we only reported errors for the forms fields, or "children". This commit changes `h.accounts.views.validate_form` so that it converts the entire `colander.Invalid` object into a dictionary using its `asdict()` instance method. By doing this, we get two immediate benefits: - top-level validation errors are reported in the '' (empty string) field - we avoid the need to aggregate form field errors by hand in ajax_form In addition, we need to deal with this case on the frontend, so this commit also changes the formRespond directive so that if no overall "reason" is provided for failure, then an empty-string member of the "errors" object can set the overall validation status (and error message) for the form.
- Loading branch information
1 parent
da8ac11
commit 5b49aab
Showing
4 changed files
with
42 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters