Ticket #16479: 16479-formset-forms-error_class-with-tests.diff

File 16479-formset-forms-error_class-with-tests.diff, 1.8 KB (added by Simon Charette, 13 years ago)

fix + tests

  • tests/regressiontests/forms/tests/formsets.py

     
    11# -*- coding: utf-8 -*-
    22from django.forms import Form, CharField, IntegerField, ValidationError, DateField
    33from django.forms.formsets import formset_factory, BaseFormSet
     4from django.forms.util import ErrorList
    45from django.utils.unittest import TestCase
    56
    67
     
    805806        self.assertEqual(str(reverse_formset[1]), str(forms[-2]))
    806807        self.assertEqual(len(reverse_formset), len(forms))
    807808
     809    def test_formset_error_class(self):
     810        # Regression tests for #16479 -- formsets form use ErrorList instead of supplied error_class
     811        class CustomErrorList(ErrorList):
     812            pass
     813       
     814        formset = FavoriteDrinksFormSet(error_class=CustomErrorList)
     815        self.assertEqual(formset.forms[0].error_class, CustomErrorList)
     816
    808817data = {
    809818    'choices-TOTAL_FORMS': '1', # the number of forms rendered
    810819    'choices-INITIAL_FORMS': '0', # the number of forms with initial data
  • django/forms/formsets.py

     
    111111        """
    112112        Instantiates and returns the i-th form instance in a formset.
    113113        """
    114         defaults = {'auto_id': self.auto_id, 'prefix': self.add_prefix(i)}
     114        defaults = {
     115            'auto_id': self.auto_id,
     116                   'prefix': self.add_prefix(i),
     117                   'error_class': self.error_class,
     118               }
    115119        if self.is_bound:
    116120            defaults['data'] = self.data
    117121            defaults['files'] = self.files
Back to Top