summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2017-04-15 13:01:38 -0400
committerTim Graham <timograham@gmail.com>2017-04-17 08:32:29 -0400
commitc09bf8d76770d39a4d9545b67598cd05adee281b (patch)
tree209391e0482730712a18d450d72b654b985e7158
parente5dce7b0fbd2965e524ce97114f501319ec2bb6f (diff)
Fixed #28058 -- Restored empty BoundFields evaluating to True.
Regression in b52c73008a9d67e9ddbb841872dc15cdd3d6ee01
-rw-r--r--django/forms/boundfield.py4
-rw-r--r--docs/releases/1.11.1.txt3
-rw-r--r--tests/forms_tests/tests/test_forms.py7
3 files changed, 14 insertions, 0 deletions
diff --git a/django/forms/boundfield.py b/django/forms/boundfield.py
index 9c0cd6e427..f3f6e3aea0 100644
--- a/django/forms/boundfield.py
+++ b/django/forms/boundfield.py
@@ -53,6 +53,10 @@ class BoundField:
for widget in self.field.widget.subwidgets(self.html_name, self.value(), attrs=attrs)
)
+ def __bool__(self):
+ # BoundField evaluates to True even if it doesn't have subwidgets.
+ return True
+
def __iter__(self):
return iter(self.subwidgets)
diff --git a/docs/releases/1.11.1.txt b/docs/releases/1.11.1.txt
index e7f2638881..953a6e8889 100644
--- a/docs/releases/1.11.1.txt
+++ b/docs/releases/1.11.1.txt
@@ -24,3 +24,6 @@ Bugfixes
* Fixed empty POST data table appearing instead of "No POST data" in HTML debug
page (:ticket:`28079`).
+
+* Restored ``BoundField``\s without any ``choices`` evaluating to ``True``
+ (:ticket:`28058`).
diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py
index 2466bbc67b..9f32953b47 100644
--- a/tests/forms_tests/tests/test_forms.py
+++ b/tests/forms_tests/tests/test_forms.py
@@ -746,6 +746,13 @@ Java</label></li>
[str(bf[1]), str(bf[2]), str(bf[3])],
)
+ def test_boundfield_bool(self):
+ """BoundField without any choices (subwidgets) evaluates to True."""
+ class TestForm(Form):
+ name = ChoiceField(choices=[])
+
+ self.assertIs(bool(TestForm()['name']), True)
+
def test_forms_with_multiple_choice(self):
# MultipleChoiceField is a special case, as its data is required to be a list:
class SongForm(Form):