#5843 closed Uncategorized (fixed)
Newforms > Provide example of how to do Form.clean_fieldname() and Form.clean()
Reported by: | anonymous | Owned by: | |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | newforms |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
It would be helpful to show an example of how to implement your own clean_fieldname() and clean() methods for subclassed forms. (N.B. An example of how to clean a subclassed field IS shown - ie field.clean(self, value))
Presumably cleaning should be done by using the .data attribute of forms, although .data doesn't appear to be documented.
Attachments (1)
Change History (8)
comment:1 by , 17 years ago
comment:2 by , 17 years ago
Has patch: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
Triage Stage: | Unreviewed → Accepted |
All you need to know is here:
http://www.djangoproject.com/documentation/newforms/#custom-form-and-field-validation
But, you are right an example of Form.clean() would be good. I took this one
from tests/regressiontests/forms/forms.py.
The patch is attached.
comment:3 by , 17 years ago
Cc: | added |
---|
comment:4 by , 17 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:5 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:6 by , 16 years ago
comment:7 by , 13 years ago
Cc: | removed |
---|---|
Easy pickings: | unset |
Severity: | → Normal |
Type: | → Uncategorized |
UI/UX: | unset |
Cleaning should not be done using .data, as custom functions run after the default.
As such,
cleaned_data
will already be populated for the field(s) in question, and should be used instead :)