Opened 10 years ago

Closed 9 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@… 10 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@… 10 years ago.
Sample DivForm class implementation with as_div() shortcut method.
div-form.2.diff (3.4 KB) - added by michal@… 10 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 Chris Beaven 10 years ago.
simpler version with tests and first-pass docs

Download all attachments as: .zip

Change History (8)

Changed 10 years ago by michal@…

Attachment: div-form.diff added

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

Changed 10 years ago by michal@…

Attachment: div-forms.py added

Sample DivForm class implementation with as_div() shortcut method.

comment:1 Changed 10 years ago by Malcolm Tredinnick

Has patch: set
Needs documentation: set
Needs tests: set
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

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 10 years ago by michal@…

Attachment: div-form.2.diff added

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

comment:2 Changed 10 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 10 years ago by Chris Beaven

Attachment: div-form.3.diff added

simpler version with tests and first-pass docs

comment:3 Changed 10 years ago by Chris Beaven

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:4 Changed 9 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

(In [6142]) Fixed #4752 -- Make default ErrorList customisable in newforms display. Based on a patch from michal@… and SmileyChris.

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