Code

Opened 7 years ago

Closed 7 years ago

#4752 closed (fixed)

Allow arbitrary ErrorList class in BaseForm._html_output

Reported by: michal@… Owned by: nobody
Component: Forms Version: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I realised there is no intent to support "clean" webdesign approach with as_div() shortcuts in BaseForm class as per ticket 3286. Too sad I must say...

Anyway I inherited BaseForm to my own Form implementation that produces clean CSS-able <div></div> output, where the only problem remains with error messages being <ul>-list. Attached is a patch that enables passing my own ErrorList implementation with <div/> support to _html_output() and wraps it all up to a completely <div/>-ed Form. Second attachment is shows my DivForm class and accompanying DivErrorList class.

Attachments (4)

div-form.diff (1.2 KB) - added by michal@… 7 years ago.
Patch that adds a parameter to _html_output to allow using arbitrary ErrorList class implementation
div-forms.py (1.2 KB) - added by michal@… 7 years ago.
Sample DivForm class implementation with as_div() shortcut method.
div-form.2.diff (3.4 KB) - added by michal@… 7 years ago.
Patch that adds a parameter to BaseForm.init constructor to allow using arbitrary ErrorList class implementation
div-form.3.diff (5.2 KB) - added by SmileyChris 7 years ago.
simpler version with tests and first-pass docs

Download all attachments as: .zip

Change History (8)

Changed 7 years ago by michal@…

Patch that adds a parameter to _html_output to allow using arbitrary ErrorList class implementation

Changed 7 years ago by michal@…

Sample DivForm class implementation with as_div() shortcut method.

comment:1 Changed 7 years ago by mtredinnick

  • Has patch set
  • Needs documentation set
  • Needs tests set
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

I've been thinking that we might need something like this for a while, too. The first patch is almost exactly what I had in mind, although we'll probably use a shorter parameter name in the final commit. Needs a test (in regressiontests/forms/tests.py) and documentation (docs/newforms.txt) to be complete.

Not sure what the second patch is for. You might want to put that in the wiki as an example after the first patch is commited?

Changed 7 years ago by michal@…

Patch that adds a parameter to BaseForm.init constructor to allow using arbitrary ErrorList class implementation

comment:2 Changed 7 years ago by michal@…

In the previous comment is attached an improved patch that converts all other ErrorList usages. Works fine with NON_FIELD_ERRORS as well now.

Changed 7 years ago by SmileyChris

simpler version with tests and first-pass docs

comment:3 Changed 7 years ago by SmileyChris

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Accepted to Ready for checkin

comment:4 Changed 7 years ago by mtredinnick

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

(In [6142]) Fixed #4752 -- Make default ErrorList customisable in newforms display. Based on a patch from michal@… and 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.