mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #26534 -- Fixed boolean form fields has_changed() with hidden input.
This commit is contained in:
committed by
Simon Charette
parent
188883048e
commit
218175b09d
@@ -720,12 +720,9 @@ class BooleanField(Field):
|
||||
raise ValidationError(self.error_messages['required'], code='required')
|
||||
|
||||
def has_changed(self, initial, data):
|
||||
# Sometimes data or initial could be None or '' which should be the
|
||||
# same thing as False.
|
||||
if initial == 'False':
|
||||
# show_hidden_initial may have transformed False to 'False'
|
||||
initial = False
|
||||
return bool(initial) != bool(data)
|
||||
# Sometimes data or initial may be a string equivalent of a boolean
|
||||
# so we should run it through to_python first to get a boolean value
|
||||
return self.to_python(initial) != self.to_python(data)
|
||||
|
||||
|
||||
class NullBooleanField(BooleanField):
|
||||
@@ -754,14 +751,6 @@ class NullBooleanField(BooleanField):
|
||||
def validate(self, value):
|
||||
pass
|
||||
|
||||
def has_changed(self, initial, data):
|
||||
# None (unknown) and False (No) are not the same
|
||||
if initial is not None:
|
||||
initial = bool(initial)
|
||||
if data is not None:
|
||||
data = bool(data)
|
||||
return initial != data
|
||||
|
||||
|
||||
class CallableChoiceIterator(object):
|
||||
def __init__(self, choices_func):
|
||||
|
||||
Reference in New Issue
Block a user