Ticket #15912: 15912.diff
File 15912.diff, 2.0 KB (added by , 13 years ago) |
---|
-
tests/regressiontests/forms/tests/fields.py
36 36 from django.forms.widgets import RadioFieldRenderer 37 37 from django.utils.unittest import TestCase 38 38 39 40 39 def fix_os_paths(x): 41 40 if isinstance(x, basestring): 42 41 return x.replace('\\', '/') … … 109 108 self.assertEqual(f.max_length, None) 110 109 self.assertEqual(f.min_length, 10) 111 110 111 def test_charfield_widget_attrs(self): 112 f = CharField() 113 # Return an empty dictionary if min_length is None 114 self.assertEqual(f.widget_attrs(TextInput()), {}) 115 116 # Or if the widget is not TextInput or PasswordInput 117 f = CharField(max_length=10) 118 self.assertEqual(f.widget_attrs(HiddenInput()), {}) 119 120 # Otherwise, should return a maxlength attribute equal to max_length 121 self.assertEqual(f.widget_attrs(TextInput()), {'maxlength': '10'}) 122 self.assertEqual(f.widget_attrs(PasswordInput()), {'maxlength': '10'}) 123 124 f = CharField(max_length=20) 125 self.assertEqual(f.widget_attrs(TextInput()), {'maxlength': '20'}) 126 self.assertEqual(f.widget_attrs(PasswordInput()), {'maxlength': '20'}) 127 112 128 # IntegerField ################################################################ 113 129 114 130 def test_integerfield_1(self): -
django/forms/fields.py
199 199 if self.max_length is not None and isinstance(widget, (TextInput, PasswordInput)): 200 200 # The HTML attribute is maxlength, not max_length. 201 201 return {'maxlength': str(self.max_length)} 202 else: 203 return {} 202 204 203 205 class IntegerField(Field): 204 206 default_error_messages = {