Opened 18 years ago
Closed 18 years ago
#3026 closed enhancement (fixed)
[patch] Newforms - suppress errors if no data passed in
Reported by: | Chris Beaven | Owned by: | Adrian Holovaty |
---|---|---|---|
Component: | Forms | Version: | |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
It would be helpful if there was an easy way of not using errors if it's a form with no passed data
My suggestion is that if data is None
when in the Form
is initialized, then errors should be suppressed (this way, you could pass an empty dict still if you want the errors initially).
Attachments (2)
Change History (11)
comment:1 by , 18 years ago
comment:2 by , 18 years ago
Whoop, I meant:
Is the distinction between as_ul()
and as_ul_with_errors()
not enough? What's the use-case for this?
comment:3 by , 18 years ago
The problem is I have a template which wants to use a form. The form is rendered from my view. I want to pass the form through and do the work in the template.
Without the ignoring of errors, the form (pre-post) will contain validation errors.
comment:4 by , 18 years ago
Expanding: It seems to make sense that I can use the same form for the initial display, and displaying it again if there was any validation errors.
In fact, then you wouldn't need the separation of the helper functions between error and non-error versions. They can always be 'with_errors' as such. Having the two different functions is a bit naff really, as then either the view has to make the decision and pass HTML to the template, or the template has to know whether it's a fresh form or one requiring validation.
by , 18 years ago
Attachment: | newforms_errors.patch added |
---|
by , 18 years ago
Attachment: | newforms_errors.2.patch added |
---|
comment:5 by , 18 years ago
Summary: | Newforms - suppress errors if no data passed in → [patch] Newforms - suppress errors if no data passed in |
---|
(ignore that newforms.patch
, wrong file selected)
Here's my take on it anyway.
- Changed
Form.errors
to be a property (was a function) to matchBoundField
's format - Removed a redundant
Form.clean()
function which was being replaced by the one at the end Form
ignores errors ifdata == None
- Replaced the non-error checking
as_table
andas_ul
functions with their_with_errors
counterparts - Updated tests
comment:6 by , 18 years ago
Component: | Core framework → django.newforms |
---|
comment:7 by , 18 years ago
comment:8 by , 18 years ago
comment:9 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Is the distinction between
as_ul()
andas_ul_with_errors()
isn't enough? What's the use-case for this?