mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #17051 -- Removed some 'invalid' field error messages
When the 'invalid' error message is set at field level, it masks the error message raised by the validator, if any.
This commit is contained in:
@@ -181,24 +181,20 @@ the field's ``validators`` argument, or defined on the Field class itself with
|
||||
the ``default_validators`` attribute.
|
||||
|
||||
Simple validators can be used to validate values inside the field, let's have
|
||||
a look at Django's ``EmailField``::
|
||||
a look at Django's ``SlugField``::
|
||||
|
||||
class EmailField(CharField):
|
||||
default_error_messages = {
|
||||
'invalid': _('Enter a valid email address.'),
|
||||
}
|
||||
default_validators = [validators.validate_email]
|
||||
class SlugField(CharField):
|
||||
default_validators = [validators.validate_slug]
|
||||
|
||||
As you can see, ``EmailField`` is just a ``CharField`` with customized error
|
||||
message and a validator that validates email addresses. This can also be done
|
||||
on field definition so::
|
||||
As you can see, ``SlugField`` is just a ``CharField`` with a customized
|
||||
validator that validates that submitted text obeys to some character rules.
|
||||
This can also be done on field definition so::
|
||||
|
||||
email = forms.EmailField()
|
||||
slug = forms.SlugField()
|
||||
|
||||
is equivalent to::
|
||||
|
||||
email = forms.CharField(validators=[validators.validate_email],
|
||||
error_messages={'invalid': _('Enter a valid email address.')})
|
||||
slug = forms.CharField(validators=[validators.validate_slug])
|
||||
|
||||
|
||||
Form field default cleaning
|
||||
|
||||
Reference in New Issue
Block a user