Opened 5 years ago

Closed 4 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 5 years ago.
16479-formset-forms-error_class-with-tests.diff (1.8 KB) - added by Simon Charette 5 years ago.
fix + tests
16479-formset-forms-error_class-with-tests_updated.diff (1.7 KB) - added by Ludovic Delaveau 4 years ago.
Updated test import

Download all attachments as: .zip

Change History (13)

comment:1 Changed 5 years ago by anonymous

Changed 5 years ago by Simon Charette

comment:2 Changed 5 years ago by Simon Charette

Needs tests: set

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

comment:3 Changed 5 years ago by Aymeric Augustin

Triage Stage: UnreviewedAccepted

Changed 5 years ago by Simon Charette

fix + tests

comment:4 Changed 5 years ago by Simon Charette

Added a patch with fix and tests.

comment:5 Changed 5 years ago by Simon Charette

Owner: changed from nobody to Simon Charette
Status: newassigned

Changed 4 years ago by Ludovic Delaveau

Updated test import

comment:6 Changed 4 years ago by Ludovic Delaveau

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

comment:7 Changed 4 years ago by Ludovic Delaveau

Needs tests: unset

comment:8 Changed 4 years ago by Ludovic Delaveau

Cc: Ludovic Delaveau added

comment:9 Changed 4 years ago by Ludovic Delaveau

Triage Stage: AcceptedReady for checkin

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

comment:10 Changed 4 years ago by Luke Plant <L.Plant.98@…>

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