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)

newforms_errors.patch (10.2 KB ) - added by Chris Beaven 18 years ago.
newforms_errors.2.patch (10.9 KB ) - added by Chris Beaven 18 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 by Adrian Holovaty, 18 years ago

Is the distinction between as_ul() and as_ul_with_errors() isn't enough? What's the use-case for this?

comment:2 by Adrian Holovaty, 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 Chris Beaven, 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 Chris Beaven, 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 Chris Beaven, 18 years ago

Attachment: newforms_errors.patch added

by Chris Beaven, 18 years ago

Attachment: newforms_errors.2.patch added

comment:5 by Chris Beaven, 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 match BoundField's format
  • Removed a redundant Form.clean() function which was being replaced by the one at the end
  • Form ignores errors if data == None
  • Replaced the non-error checking as_table and as_ul functions with their _with_errors counterparts
  • Updated tests

comment:6 by Adrian Holovaty, 18 years ago

Component: Core frameworkdjango.newforms

comment:7 by Adrian Holovaty, 18 years ago

(In [4116]) newforms: Changed Form.errors to be a property rather than a function. Refs #3026

comment:8 by Adrian Holovaty, 18 years ago

(In [4115]) newforms: Removed redundant declaration of Form.clean(). Thanks, SmileyChris. Refs #3026

comment:9 by Adrian Holovaty, 18 years ago

Resolution: fixed
Status: newclosed

(In [4117]) Fixed #3026 -- newforms: Form class now suppresses validation and errors if no data (or None) is passed in. Validation still happens if you pass in an empty dictionary. Also updated unit tests. Thanks, SmileyChris

Note: See TracTickets for help on using tickets.
Back to Top