From aaecf038cae61f114db396f74e06759c95f21e93 Mon Sep 17 00:00:00 2001
From: Josef Rousek
Date: Sat, 5 Nov 2016 12:27:44 +0100
Subject: [PATCH] Fixed #27370 -- Prevented Select widget from using 'required'
with a non-empty first value.
---
AUTHORS | 1 +
django/forms/widgets.py | 22 ++++++++++
.../field_tests/test_choicefield.py | 2 +-
tests/forms_tests/tests/test_forms.py | 40 +++++++++----------
tests/forms_tests/tests/tests.py | 8 ++--
tests/forms_tests/widget_tests/test_select.py | 20 ++++++++++
tests/model_forms/tests.py | 4 +-
7 files changed, 70 insertions(+), 27 deletions(-)
diff --git a/AUTHORS b/AUTHORS
index ff17d1a418..82938eea88 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -397,6 +397,7 @@ answer newbie questions, and generally made Django that much better:
Jorge Bastida
Jorge Gajon
José Tomás Tocino García
+ Josef Rousek
Joseph Kocherhans
Josh Smeaton
Joshua Ginsberg
diff --git a/django/forms/widgets.py b/django/forms/widgets.py
index dd68662d43..4f028d34ad 100644
--- a/django/forms/widgets.py
+++ b/django/forms/widgets.py
@@ -680,6 +680,28 @@ class Select(ChoiceWidget):
context['widget']['attrs']['multiple'] = 'multiple'
return context
+ @staticmethod
+ def _choice_has_empty_value(choice):
+ """Return True if the choice's value is empty string or None."""
+ value, _ = choice
+ return (
+ (isinstance(value, six.string_types) and not bool(value)) or
+ value is None
+ )
+
+ def use_required_attribute(self, initial):
+ """
+ Don't render 'required' if the first
"""
-