Ticket #5104: checkboxinput.2.patch
File checkboxinput.2.patch, 2.6 KB (added by , 17 years ago) |
---|
-
django/newforms/widgets.py
153 153 final_attrs['value'] = force_unicode(value) # Only add the 'value' attribute if a value is non-empty. 154 154 return u'<input%s />' % flatatt(final_attrs) 155 155 156 def value_from_datadict(self, data, name): 157 if name not in data: 158 # A missing value returns False because it simply means the check 159 # box wasn't checked. 160 return False 161 return super(CheckboxInput, self).value_from_datadict(data, name) 162 156 163 class Select(Widget): 157 164 def __init__(self, attrs=None, choices=()): 158 165 self.attrs = attrs or {} -
docs/newforms.txt
1015 1015 ~~~~~~~~~~~~~~~~ 1016 1016 1017 1017 * Default widget: ``CheckboxInput`` 1018 * Empty value: `` None``1018 * Empty value: ``False`` 1019 1019 * Normalizes to: A Python ``True`` or ``False`` value. 1020 * Validates nothing (i.e., it never raises a ``ValidationError``).1021 1020 1022 1021 ``CharField`` 1023 1022 ~~~~~~~~~~~~~ … … 1025 1024 * Default widget: ``TextInput`` 1026 1025 * Empty value: ``''`` (an empty string) 1027 1026 * Normalizes to: A Unicode object. 1028 * Validates nothing, unless ``max_length`` or ``min_length`` isprovided.1027 * Validates ``max_length`` and ``min_length`` if they are provided. 1029 1028 1030 1029 Has two optional arguments for validation, ``max_length`` and ``min_length``. 1031 1030 If provided, these arguments ensure that the string is at most or at least the … … 1126 1125 * Default widget: ``NullBooleanSelect`` 1127 1126 * Empty value: ``None`` 1128 1127 * Normalizes to: A Python ``True``, ``False`` or ``None`` value. 1129 * Validates nothing (i.e., it never raises a ``ValidationError``).1130 1128 1131 1129 ``RegexField`` 1132 1130 ~~~~~~~~~~~~~~ -
tests/regressiontests/forms/tests.py
276 276 >>> w.render('greeting', None) 277 277 u'<input type="checkbox" name="greeting" />' 278 278 279 Note that the CheckboxInput widget will return False if the key is not found in 280 the data dict. 281 >>> print w.value_from_datadict({'testing':None}, 'testing') 282 None 283 >>> print w.value_from_datadict({}, 'testing') 284 False 285 279 286 # Select Widget ############################################################### 280 287 281 288 >>> w = Select()