Opened 4 years ago

Closed 2 years ago

#16479 closed Bug (fixed)

Forms generated from formsets use ErrorList instead of supplied error_class

Reported by: marcin.tustin@… Owned by: charettes
Component: Forms Version: 1.3
Severity: Normal Keywords: forms formsets
Cc: vicould 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 charettes 4 years ago.
16479-formset-forms-error_class-with-tests.diff (1.8 KB) - added by charettes 4 years ago.
fix + tests
16479-formset-forms-error_class-with-tests_updated.diff (1.7 KB) - added by vicould 2 years ago.
Updated test import

Download all attachments as: .zip

Change History (13)

comment:1 Changed 4 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Changed 4 years ago by charettes

comment:2 Changed 4 years ago by charettes

  • Needs tests set

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

comment:3 Changed 4 years ago by aaugustin

  • Triage Stage changed from Unreviewed to Accepted

Changed 4 years ago by charettes

fix + tests

comment:4 Changed 4 years ago by charettes

Added a patch with fix and tests.

comment:5 Changed 4 years ago by charettes

  • Owner changed from nobody to charettes
  • Status changed from new to assigned

Changed 2 years ago by vicould

Updated test import

comment:6 Changed 2 years ago by vicould

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 2 years ago by vicould

  • Needs tests unset

comment:8 Changed 2 years ago by vicould

  • Cc vicould added

comment:9 Changed 2 years ago by vicould

  • Triage Stage changed from Accepted to Ready for checkin

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

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

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

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