[1.11.x] Fixed #28176 -- Restored the uncasted option value in ChoiceWidget template context.
Backport of 221e6e1817
from master
This commit is contained in:
parent
f0ec88fb63
commit
a3b1319d58
|
@ -1 +1 @@
|
||||||
<input type="{{ widget.type }}" name="{{ widget.name }}"{% if widget.value != None %} value="{{ widget.value }}"{% endif %}{% include "django/forms/widgets/attrs.html" %} />
|
<input type="{{ widget.type }}" name="{{ widget.name }}"{% if widget.value != None %} value="{{ widget.value|stringformat:'s' }}"{% endif %}{% include "django/forms/widgets/attrs.html" %} />
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
<option value="{{ widget.value }}"{% include "django/forms/widgets/attrs.html" %}>{{ widget.label }}</option>
|
<option value="{{ widget.value|stringformat:'s' }}"{% include "django/forms/widgets/attrs.html" %}>{{ widget.label }}</option>
|
||||||
|
|
|
@ -611,7 +611,7 @@ class ChoiceWidget(Widget):
|
||||||
option_attrs['id'] = self.id_for_label(option_attrs['id'], index)
|
option_attrs['id'] = self.id_for_label(option_attrs['id'], index)
|
||||||
return {
|
return {
|
||||||
'name': name,
|
'name': name,
|
||||||
'value': force_text(value),
|
'value': value,
|
||||||
'label': label,
|
'label': label,
|
||||||
'selected': selected,
|
'selected': selected,
|
||||||
'index': index,
|
'index': index,
|
||||||
|
|
|
@ -44,3 +44,10 @@ Bugfixes
|
||||||
* Prevented attribute values in the ``django/forms/widgets/attrs.html``
|
* Prevented attribute values in the ``django/forms/widgets/attrs.html``
|
||||||
template from being localized so that numeric attributes (e.g. ``max`` and
|
template from being localized so that numeric attributes (e.g. ``max`` and
|
||||||
``min``) of ``NumberInput`` work correctly (:ticket:`28303`).
|
``min``) of ``NumberInput`` work correctly (:ticket:`28303`).
|
||||||
|
|
||||||
|
* Removed casting of the option value to a string in the template context of
|
||||||
|
the ``CheckboxSelectMultiple``, ``NullBooleanSelect``, ``RadioSelect``,
|
||||||
|
``SelectMultiple``, and ``Select`` widgets (:ticket:`28176`). In Django
|
||||||
|
1.11.1, casting was added in Python to avoid localization of numeric values
|
||||||
|
in Django templates, but this made some use cases more difficult. Casting is
|
||||||
|
now done in the template using the ``|stringformat:'s'`` filter.
|
||||||
|
|
|
@ -351,6 +351,12 @@ class SelectTest(WidgetTest):
|
||||||
)
|
)
|
||||||
self.assertEqual(index, 2)
|
self.assertEqual(index, 2)
|
||||||
|
|
||||||
|
def test_optgroups_integer_choices(self):
|
||||||
|
"""The option 'value' is the same type as what's in `choices`."""
|
||||||
|
groups = list(self.widget(choices=[[0, 'choice text']]).optgroups('name', ['vhs']))
|
||||||
|
label, options, index = groups[0]
|
||||||
|
self.assertEqual(options[0]['value'], 0)
|
||||||
|
|
||||||
def test_deepcopy(self):
|
def test_deepcopy(self):
|
||||||
"""
|
"""
|
||||||
__deepcopy__() should copy all attributes properly (#25085).
|
__deepcopy__() should copy all attributes properly (#25085).
|
||||||
|
|
Loading…
Reference in New Issue