#28308: In 1.11 does not call the function render_option in custom widget
(forms.widgets.Select)
-------------------------------------+-------------------------------------
Reporter: noxxer | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.11
Severity: Normal | Keywords: forms, widgets,
Triage Stage: | Select, render_option
Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 1 |
-------------------------------------+-------------------------------------
Checked and compared the rendering of the form in 1.10 and 1.11. In
version 1.11, the method render_option ceased to be called.
{{{
class SelectWithData(forms.widgets.Select):
def __init__(self, *args, **kwargs):
self.options_data = kwargs.pop('options_data', None)
super(SelectWithData, self).__init__(*args, **kwargs)
def render_option(self, selected_choices, option_value, option_label):
if self.options_data and option_value in self.options_data:
price=''
if 'price' in self.options_data[option_value]:
price = self.options_data[option_value]['price']
html = u'<option value="{}" price="{}" >{}</option>'.format(
escape(option_value),
price,
conditional_escape(force_unicode(option_label)))
else:
# No options_data
option_value = force_unicode(option_value)
html = u'<option value="{}">{}</option>'.format(
escape(option_value),
conditional_escape(force_unicode(option_label)))
return html
class MyForm(forms.Form):
state = forms.ChoiceField(widget=forms.SelectWithData(choices=[]))
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28308>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.04ba7e693294562af145283cab44b0bf%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.