diff --git a/django/forms/fields.py b/django/forms/fields.py
index 113a5aa..f1b0a1b 100644
a
|
b
|
class CharField(Field):
|
197 | 197 | if self.max_length is not None and isinstance(widget, (TextInput, PasswordInput)): |
198 | 198 | # The HTML attribute is maxlength, not max_length. |
199 | 199 | return {'maxlength': str(self.max_length)} |
| 200 | else: |
| 201 | return {} |
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): |