Fixed #16479 - Forms generated from formsets use ErrorList instead of supplied error_class
Patch with tests from charettes, updated.
This commit is contained in:
parent
cc83a4af0c
commit
7a44dc555a
|
@ -123,7 +123,11 @@ class BaseFormSet(object):
|
||||||
"""
|
"""
|
||||||
Instantiates and returns the i-th form instance in a formset.
|
Instantiates and returns the i-th form instance in a formset.
|
||||||
"""
|
"""
|
||||||
defaults = {'auto_id': self.auto_id, 'prefix': self.add_prefix(i)}
|
defaults = {
|
||||||
|
'auto_id': self.auto_id,
|
||||||
|
'prefix': self.add_prefix(i),
|
||||||
|
'error_class': self.error_class,
|
||||||
|
}
|
||||||
if self.is_bound:
|
if self.is_bound:
|
||||||
defaults['data'] = self.data
|
defaults['data'] = self.data
|
||||||
defaults['files'] = self.files
|
defaults['files'] = self.files
|
||||||
|
|
|
@ -3,6 +3,7 @@ from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.forms import Form, CharField, IntegerField, ValidationError, DateField
|
from django.forms import Form, CharField, IntegerField, ValidationError, DateField
|
||||||
from django.forms.formsets import formset_factory, BaseFormSet
|
from django.forms.formsets import formset_factory, BaseFormSet
|
||||||
|
from django.forms.util import ErrorList
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
|
|
||||||
|
@ -847,6 +848,15 @@ class FormsFormsetTestCase(TestCase):
|
||||||
self.assertTrue(formset)
|
self.assertTrue(formset)
|
||||||
|
|
||||||
|
|
||||||
|
def test_formset_error_class(self):
|
||||||
|
# Regression tests for #16479 -- formsets form use ErrorList instead of supplied error_class
|
||||||
|
class CustomErrorList(ErrorList):
|
||||||
|
pass
|
||||||
|
|
||||||
|
formset = FavoriteDrinksFormSet(error_class=CustomErrorList)
|
||||||
|
self.assertEqual(formset.forms[0].error_class, CustomErrorList)
|
||||||
|
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'choices-TOTAL_FORMS': '1', # the number of forms rendered
|
'choices-TOTAL_FORMS': '1', # the number of forms rendered
|
||||||
'choices-INITIAL_FORMS': '0', # the number of forms with initial data
|
'choices-INITIAL_FORMS': '0', # the number of forms with initial data
|
||||||
|
|
Loading…
Reference in New Issue