Ticket #5959: boolean_hidden.diff
File boolean_hidden.diff, 2.2 KB (added by , 17 years ago) |
---|
-
django/newforms/fields.py
538 538 def clean(self, value): 539 539 "Returns a Python boolean object." 540 540 super(BooleanField, self).clean(value) 541 # Explicitly check for the string ' 0', which is what as hidden field541 # Explicitly check for the string 'False', which is what as hidden field 542 542 # will submit for False. 543 if value == ' 0':543 if value == 'False': 544 544 return False 545 545 return bool(value) 546 546 -
tests/regressiontests/forms/fields.py
914 914 >>> f.clean('Django rocks') 915 915 True 916 916 917 A form's BooleanField with a hidden widget will output the string 'False', so 918 that should clean to the boolean value False: 919 >>> f.clean('False') 920 False 921 917 922 >>> f = BooleanField(required=False) 918 923 >>> f.clean('') 919 924 False … … 930 935 >>> f.clean('Django rocks') 931 936 True 932 937 938 A form's BooleanField with a hidden widget will output the string 'False', so 939 that should clean to the boolean value False: 940 >>> f.clean('False') 941 False 942 933 943 # ChoiceField ################################################################# 934 944 935 945 >>> f = ChoiceField(choices=[('1', '1'), ('2', '2')]) -
tests/regressiontests/forms/widgets.py
128 128 >>> w.render('email', '', attrs={'class': 'special'}) 129 129 u'<input type="hidden" class="special" name="email" />' 130 130 131 Still renders the boolean value False as the string 'False', it's the job of the 132 field to clean that back to a boolean False if required. 133 >>> w = HiddenInput() 134 >>> w.render('get_spam', False) 135 u'<input type="hidden" name="get_spam" value="False" />' 136 131 137 # MultipleHiddenInput Widget ################################################## 132 138 133 139 >>> w = MultipleHiddenInput()