-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move validation from widgets to the form fields
Previously, the widgets handled part of the validation. That behavior prevents overriding validation in form fields, as widgets were casting the value into a `PhoneNumber` object, validating it in the process. Following the `MultiValueField` implementation from Django (and `MultiWidget`), the widget now handles the presentation logic, but makes no attempt at validation. The new `SplitPhoneNumberField` handles the logic of validating the region choice and the number, and the `PhoneNumberPrefixWidget` simply dispatches the region and number data to the appropriate widget. In order to retain backward compatibility, now that the `validate_international_phonenumber` actually comes into play, it’s error code has been changed to `invalid`, so that the custom error message for invalid shows. Migration guide =============== `validate_international_phonenumber` ------------------------------------ Review uses of the `invalid_phone_number` error code. Given that the validator usually did not come into play, you shouldn’t find many uses. `PhoneNumberField` with `RegionalPhoneNumberWidget` --------------------------------------------------- Make sure custom validation occurs in the Django `Form` `clean_FIELD()` (or `clean()`), and no changes should be noticeable. `PhoneNumberField` with `PhoneNumberPrefixWidget` ------------------------------------------------- Use the `SplitPhoneNumberField` instead. Error messages will change slightly and should be more precise (whether the region is not part of the choices, or the number cannot be interpreted in the selected region). For more examples, take a look at `tests.test_formfields.SplitPhoneNumberFieldTest`. In particular `test_custom_attrs` and `test_custom_choices`, to see how they were migrated to the new field.
- Loading branch information
1 parent
e491d09
commit 9923578
Showing
6 changed files
with
723 additions
and
501 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
Oops, something went wrong.