Ticket #11303: show_hidden_initial_boolean.diff
File show_hidden_initial_boolean.diff, 1.9 KB (added by , 15 years ago) |
---|
-
django/forms/widgets.py
386 386 387 387 def _has_changed(self, initial, data): 388 388 # Sometimes data or initial could be None or u'' which should be the 389 # same thing as False. 389 # same thing as False. If show_hidden_initial is true on the field then 390 # the initial value will come through as the string 'False' which when 391 # converted to boolean returns True 392 if initial == 'False': 393 initial = False 390 394 return bool(initial) != bool(data) 391 395 392 396 class Select(Widget): -
tests/regressiontests/forms/forms.py
1795 1795 >>> form.is_valid() 1796 1796 True 1797 1797 1798 1799 # BooleanFields with show_hidden_initial report changed when they haven't ####################### 1800 1801 >>> class SubscriberForm(Form): 1802 ... name = CharField(show_hidden_initial=True) 1803 ... new_subscriber = BooleanField(show_hidden_initial=True, required=False) 1804 ... 1805 >>> def my_function(method, post_data): 1806 ... if method == 'POST': 1807 ... form = SubscriberForm(post_data) 1808 ... else: 1809 ... form = SubscriberForm() 1810 ... if form.is_valid(): 1811 ... return form.changed_data 1812 ... t = Template('<form action="" method="post">\n<table>\n{{ form }}\n</table>\n<input type="submit" />\n</form>') 1813 ... return t.render(Context({'form': form})) 1814 ... 1815 >>> print my_function('POST', {'name': 'James', 'initial-name': 'James', 'new_subscriber': False, 'initial-new_subscriber': 'False'}) 1816 [] 1817 1798 1818 # Extracting hidden and visible fields ###################################### 1799 1819 1800 1820 >>> class SongForm(Form):