Ticket #19537: 19537-1.diff

File 19537-1.diff, 1.2 KB (added by claudep, 3 years ago)
  • django/forms/widgets.py

    diff --git a/django/forms/widgets.py b/django/forms/widgets.py
    index c761ea8..4782b99 100644
    a b class CheckboxInput(Widget): 
    533533    def _has_changed(self, initial, data):
    534534        # Sometimes data or initial could be None or '' which should be the
    535535        # same thing as False.
     536        if initial == 'False':
     537            # show_hidden_initial may have transformed False to 'False'
     538            initial = False
    536539        return bool(initial) != bool(data)
    537540
    538541class Select(Widget):
  • tests/regressiontests/forms/tests/widgets.py

    diff --git a/tests/regressiontests/forms/tests/widgets.py b/tests/regressiontests/forms/tests/widgets.py
    index 31c0e65..f9dc4a7 100644
    a b class FormsWidgetTestCase(TestCase): 
    240240        self.assertTrue(w._has_changed(False, 'on'))
    241241        self.assertFalse(w._has_changed(True, 'on'))
    242242        self.assertTrue(w._has_changed(True, ''))
     243        # Initial value may have mutated to a string due to show_hidden_initial (#19537)
     244        self.assertTrue(w._has_changed('False', 'on'))
    243245
    244246    def test_select(self):
    245247        w = Select()
Back to Top