Fixed #27920 -- Restored empty RadioSelect choice producing value=""
Regression in b52c73008a
.
Thanks Tim Graham for the review.
This commit is contained in:
parent
a7ec7afce1
commit
540ae68a5c
|
@ -347,13 +347,9 @@ class AdminURLFieldWidget(forms.URLInput):
|
||||||
context = super().get_context(name, value, attrs)
|
context = super().get_context(name, value, attrs)
|
||||||
context['current_label'] = _('Currently:')
|
context['current_label'] = _('Currently:')
|
||||||
context['change_label'] = _('Change:')
|
context['change_label'] = _('Change:')
|
||||||
context['widget']['href'] = smart_urlquote(context['widget']['value'])
|
context['widget']['href'] = smart_urlquote(context['widget']['value']) if value else ''
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def format_value(self, value):
|
|
||||||
value = super().format_value(value)
|
|
||||||
return force_text(value)
|
|
||||||
|
|
||||||
|
|
||||||
class AdminIntegerFieldWidget(forms.NumberInput):
|
class AdminIntegerFieldWidget(forms.NumberInput):
|
||||||
class_name = 'vIntegerField'
|
class_name = 'vIntegerField'
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
<input type="{{ widget.type }}" name="{{ widget.name }}"{% if widget.value != None and widget.value != "" %} value="{{ widget.value }}"{% endif %}{% include "django/forms/widgets/attrs.html" %} />
|
<input type="{{ widget.type }}" name="{{ widget.name }}"{% if widget.value != None %} value="{{ widget.value }}"{% endif %}{% include "django/forms/widgets/attrs.html" %} />
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
<input type="{{ widget.type }}" name="{{ widget.name }}"{% if widget.value != None and widget.value != "" %} value="{{ widget.value }}"{% endif %}{% include "django/forms/widgets/attrs.html" %} />
|
<input type="{{ widget.type }}" name="{{ widget.name }}"{% if widget.value != None %} value="{{ widget.value }}"{% endif %}{% include "django/forms/widgets/attrs.html" %} />
|
||||||
|
|
|
@ -180,8 +180,8 @@ class Widget(metaclass=MediaDefiningClass):
|
||||||
"""
|
"""
|
||||||
Return a value as it should appear when rendered in a template.
|
Return a value as it should appear when rendered in a template.
|
||||||
"""
|
"""
|
||||||
if value is None:
|
if value == '' or value is None:
|
||||||
value = ''
|
return None
|
||||||
if self.is_localized:
|
if self.is_localized:
|
||||||
return formats.localize_input(value)
|
return formats.localize_input(value)
|
||||||
return force_text(value)
|
return force_text(value)
|
||||||
|
|
|
@ -7,8 +7,10 @@ class RadioSelectTest(WidgetTest):
|
||||||
widget = RadioSelect
|
widget = RadioSelect
|
||||||
|
|
||||||
def test_render(self):
|
def test_render(self):
|
||||||
self.check_html(self.widget(choices=self.beatles), 'beatle', 'J', html=(
|
choices = (('', '------'),) + self.beatles
|
||||||
|
self.check_html(self.widget(choices=choices), 'beatle', 'J', html=(
|
||||||
"""<ul>
|
"""<ul>
|
||||||
|
<li><label><input type="radio" name="beatle" value="" /> ------</label></li>
|
||||||
<li><label><input checked type="radio" name="beatle" value="J" /> John</label></li>
|
<li><label><input checked type="radio" name="beatle" value="J" /> John</label></li>
|
||||||
<li><label><input type="radio" name="beatle" value="P" /> Paul</label></li>
|
<li><label><input type="radio" name="beatle" value="P" /> Paul</label></li>
|
||||||
<li><label><input type="radio" name="beatle" value="G" /> George</label></li>
|
<li><label><input type="radio" name="beatle" value="G" /> George</label></li>
|
||||||
|
|
|
@ -6,6 +6,13 @@ from .base import WidgetTest
|
||||||
|
|
||||||
class WidgetTests(WidgetTest):
|
class WidgetTests(WidgetTest):
|
||||||
|
|
||||||
|
def test_format_value(self):
|
||||||
|
widget = Widget()
|
||||||
|
self.assertIsNone(widget.format_value(None))
|
||||||
|
self.assertIsNone(widget.format_value(''))
|
||||||
|
self.assertEqual(widget.format_value('español'), 'español')
|
||||||
|
self.assertEqual(widget.format_value(42.5), '42.5')
|
||||||
|
|
||||||
def test_value_omitted_from_data(self):
|
def test_value_omitted_from_data(self):
|
||||||
widget = Widget()
|
widget = Widget()
|
||||||
self.assertIs(widget.value_omitted_from_data({}, {}, 'field'), True)
|
self.assertIs(widget.value_omitted_from_data({}, {}, 'field'), True)
|
||||||
|
|
Loading…
Reference in New Issue