Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#28308 closed Cleanup/optimization (fixed)

Document removal of Select.render_option()

Reported by: noxxer Owned by: nobody
Component: Documentation Version: 1.11
Severity: Normal Keywords: forms, widgets, Select, render_option
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: yes

Description

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=[]))

Change History (3)

comment:1 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: newclosed

In f2b69863:

Fixed #28308 -- Doc'd removal of Select.render_option() (refs #15667).

comment:2 by Tim Graham <timograham@…>, 7 years ago

In f20168e8:

[1.11.x] Fixed #28308 -- Doc'd removal of Select.render_option() (refs #15667).

Backport of f2b698631719c6df082a627b6f7ddf2d7f9fa751 from master

comment:3 by Tim Graham, 7 years ago

Component: FormsDocumentation
Summary: In 1.11 does not call the function render_option in custom widget (forms.widgets.Select)Document removal of Select.render_option()
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

Usually we don't document removal of undocumented APIs but I suppose it doesn't hurt here.

Note: See TracTickets for help on using tickets.
Back to Top