diff --git a/django/forms/fields.py b/django/forms/fields.py
index 113a5aa..f538ad6 100644
a
|
b
|
class CharField(Field):
|
194 | 194 | return smart_unicode(value) |
195 | 195 | |
196 | 196 | def widget_attrs(self, widget): |
| 197 | attrs = super(CharField, self).widget_attrs(widget) |
197 | 198 | if self.max_length is not None and isinstance(widget, (TextInput, PasswordInput)): |
198 | 199 | # The HTML attribute is maxlength, not max_length. |
199 | | return {'maxlength': str(self.max_length)} |
| 200 | attrs.update({'maxlength': str(self.max_length)}) |
| 201 | return attrs |
200 | 202 | |
201 | 203 | class IntegerField(Field): |
202 | 204 | default_error_messages = { |
diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/fields.py
index 6780413..9c138a8 100644
a
|
b
|
class FieldsTests(TestCase):
|
131 | 131 | self.assertEqual(f.max_length, None) |
132 | 132 | self.assertEqual(f.min_length, 10) |
133 | 133 | |
| 134 | def test_charfield_widget_attrs(self): |
| 135 | """ Regression test for #15912 """ |
| 136 | |
| 137 | # Return an empty dictionary if max_length is None |
| 138 | f = CharField() |
| 139 | self.assertEqual(f.widget_attrs(TextInput()), {}) |
| 140 | |
| 141 | # Or if the widget is not TextInput or PasswordInput |
| 142 | f = CharField(max_length=10) |
| 143 | self.assertEqual(f.widget_attrs(HiddenInput()), {}) |
| 144 | |
| 145 | # Otherwise, return a maxlength attribute equal to max_length |
| 146 | self.assertEqual(f.widget_attrs(TextInput()), {'maxlength': '10'}) |
| 147 | self.assertEqual(f.widget_attrs(PasswordInput()), {'maxlength': '10'}) |
| 148 | |
134 | 149 | # IntegerField ################################################################ |
135 | 150 | |
136 | 151 | def test_integerfield_1(self): |