#3457: Allow overriding of error message for each newforms Field type
-------------------------+--------------------------------------------------
Reporter: anonymous | Owner: adrian
Status: new | Component: django.newforms
Version: SVN | Resolution:
Keywords: | Stage: Accepted
Has_patch: 0 | Needs_docs: 0
Needs_tests: 0 | Needs_better_patch: 0
-------------------------+--------------------------------------------------
Comment (by Manoj Govindan <[EMAIL PROTECTED]>):
I tried out some code changes (and tests) for implementing a patch. One
key question I would like to see answered is how this change should affect
the behaviour of RegexField and its subclasses, say URLField. The tests
indicate that these classes expect two kind of error messages depending on
the nature of the error.
Consider the first kind of error message, raised when the value of the
field doesn't fit a given pattern. [[BR]]
{{{
>>> f = URLField()
>>> f.clean('foo')
Traceback (most recent call last):
...
ValidationError: [u'Enter a valid URL.']
}}}
The error message displayed is the one used by URLField to override the
default provided by RegexField.
Now consider the second scenario where the field is required but turns up
empty.
{{{
>>> f.clean('')
Traceback (most recent call last):
...
ValidationError: [u'This field is required.']
}}}
The error raised in this case is different (the default error defined in
the base 'Field' class is used)
If a URLField object is created with a custom error_message, should it
still fall back to the default message if value turns out to be empty?
Likewise how should a CharField object with a custom error_message behave
in such a case?
One possible solution would be to insist that custom error messages take
precedence and hence will be always used if present. I don't mind this but
I can see why others could have problems with this. Another approach would
be to "collect" errors applicable to each field and display them together
(a la Rails model validation).
The latter implementation would result in something similar to this:
{{{
>>> f.clean('')
Traceback (most recent call last):
...
ValidationError: [u'This field is required.', u'Enter a valid URL.']
}}}
--
Ticket URL: <http://code.djangoproject.com/ticket/3457#comment:3>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---