Code

Opened 8 years ago

Closed 8 years ago

#3026 closed enhancement (fixed)

[patch] Newforms - suppress errors if no data passed in

Reported by: SmileyChris Owned by: adrian
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: UI/UX:

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 SmileyChris 8 years ago.
newforms_errors.2.patch (10.9 KB) - added by SmileyChris 8 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 Changed 8 years ago by adrian

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

comment:2 Changed 8 years ago by adrian

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 Changed 8 years ago by SmileyChris

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 Changed 8 years ago by SmileyChris

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.

Changed 8 years ago by SmileyChris

Changed 8 years ago by SmileyChris

comment:5 Changed 8 years ago by SmileyChris

  • Summary changed from Newforms - suppress errors if no data passed in to [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 Changed 8 years ago by adrian

  • Component changed from Core framework to django.newforms

comment:7 Changed 8 years ago by adrian

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

comment:8 Changed 8 years ago by adrian

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

comment:9 Changed 8 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

(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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.