Ticket #5104: checkboxinput.3.patch
File checkboxinput.3.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 The CheckboxInput widget will return False if the key is not found in the data 280 dict. 281 >>> w.value_from_datadict({}, 'testing') 282 False 283 284 If the key *is* provided, it can still be None. 285 >>> print w.value_from_datadict({'testing':None}, 'testing') 286 None 287 279 288 # Select Widget ############################################################### 280 289 281 290 >>> w = Select()