Opened 17 years ago

Closed 16 years ago

Last modified 13 years ago

#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)

newforms_form_clean.diff (1.4 KB ) - added by Thomas Guettler (Home) 17 years ago.
fixed typos

Download all attachments as: .zip

Change History (8)

comment:1 by Collin Grady <cgrady@…>, 17 years ago

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 :)

comment:2 by Thomas Guettler (Home), 17 years ago

Has patch: set
Owner: changed from nobody to anonymous
Status: newassigned
Triage Stage: UnreviewedAccepted

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.

by Thomas Guettler (Home), 17 years ago

Attachment: newforms_form_clean.diff added

fixed typos

comment:3 by Thomas Güttler (Home) <guettli.djangotrac@…>, 17 years ago

Cc: hv@… added

comment:4 by Thomas Güttler (Home) <guettli.djangotrac@…>, 17 years ago

Owner: anonymous removed
Status: assignednew

comment:5 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: newclosed

(In [9177]) Added a lot more explanation about form field validation, including expanded
examples. Fixed #5843, #6652, #7428.

comment:6 by Malcolm Tredinnick, 16 years ago

(In [9180]) [1.0.X] Added a lot more explanation about form field validation, including
expanded examples. Fixed #5843, #6652, #7428.

Backport of r9177 from trunk.

comment:7 by Thomas Güttler, 13 years ago

Cc: hv@… removed
Easy pickings: unset
Severity: Normal
Type: Uncategorized
UI/UX: unset
Note: See TracTickets for help on using tickets.
Back to Top