Opened 13 years ago

Closed 12 years ago

#16479 closed Bug (fixed)

Forms generated from formsets use ErrorList instead of supplied error_class

Reported by: marcin.tustin@… Owned by: Simon Charette
Component: Forms Version: 1.3
Severity: Normal Keywords: forms formsets
Cc: Ludovic Delaveau Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Using Django 1.3, forms generated from formsets use ErrorList instead of supplied error_class.

Accordingly, even though a formset is instantiated:

directors_formset = DirectorsFormset(prefix='directors',

data=request.POST,
error_class=SideError)

Forms generated from it use the default ErrorList ul style of error rendering.

The fix is in the first line of FormSet._construct_form, which currently reads:

defaults = {'auto_id': self.auto_id, 'prefix': self.add_prefix(i)}

(https://code.djangoproject.com/browser/django/trunk/django/forms/formsets.py#L114)

This should be changed to:

defaults = {'auto_id': self.auto_id, 'prefix': self.add_prefix(i), 'error_class': self.error_class}

Which passes the error_class down to every form instantiated.

Attachments (3)

16479-formset-forms-error_class.diff (634 bytes ) - added by Simon Charette 13 years ago.
16479-formset-forms-error_class-with-tests.diff (1.8 KB ) - added by Simon Charette 13 years ago.
fix + tests
16479-formset-forms-error_class-with-tests_updated.diff (1.7 KB ) - added by Ludovic Delaveau 12 years ago.
Updated test import

Download all attachments as: .zip

Change History (13)

comment:1 by anonymous, 13 years ago

by Simon Charette, 13 years ago

comment:2 by Simon Charette, 13 years ago

Needs tests: set

Looks like a bug to me, can someone confirm? If it's accepted it'll need tests.

comment:3 by Aymeric Augustin, 13 years ago

Triage Stage: UnreviewedAccepted

by Simon Charette, 13 years ago

fix + tests

comment:4 by Simon Charette, 13 years ago

Added a patch with fix and tests.

comment:5 by Simon Charette, 13 years ago

Owner: changed from nobody to Simon Charette
Status: newassigned

by Ludovic Delaveau, 12 years ago

Updated test import

comment:6 by Ludovic Delaveau, 12 years ago

Updated part of the patch, which could not be applied anymore: changed the context of the additional import required by the test.

comment:7 by Ludovic Delaveau, 12 years ago

Needs tests: unset

comment:8 by Ludovic Delaveau, 12 years ago

Cc: Ludovic Delaveau added

comment:9 by Ludovic Delaveau, 12 years ago

Triage Stage: AcceptedReady for checkin

Looks ready for checkin, pull request at https://github.com/django/django/pull/423

comment:10 by Luke Plant <L.Plant.98@…>, 12 years ago

Resolution: fixed
Status: assignedclosed

In 7a44dc555a3c9bfd1691ebb346b91f25d2f94c7d:

Fixed #16479 - Forms generated from formsets use ErrorList instead of supplied error_class

Patch with tests from charettes, updated.

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