forms: merge monkey-patched select render into new class (#48549)
This commit is contained in:
parent
5b32656dee
commit
7138f1456b
|
@ -290,27 +290,6 @@ def checkbox_render_content(self, standalone=True):
|
|||
CheckboxWidget.render_content = checkbox_render_content
|
||||
|
||||
|
||||
def select_render_content(self):
|
||||
attrs = {'id': 'form_' + self.name}
|
||||
if self.required:
|
||||
attrs['aria-required'] = 'true'
|
||||
if self.attrs:
|
||||
attrs.update(self.attrs)
|
||||
tags = [htmltag("select", name=self.name, **attrs)]
|
||||
for object, description, key in self.options:
|
||||
if self.is_selected(object):
|
||||
selected = 'selected'
|
||||
else:
|
||||
selected = None
|
||||
if description is None:
|
||||
description = ""
|
||||
r = htmltag("option", value=key, selected=selected)
|
||||
tags.append(r + htmlescape(description) + htmltext('</option>'))
|
||||
tags.append(htmltext("</select>"))
|
||||
return htmltext("\n").join(tags)
|
||||
SelectWidget.render_content = select_render_content
|
||||
|
||||
|
||||
def get_selection_error_text(*args):
|
||||
return _('invalid value selected')
|
||||
|
||||
|
@ -982,6 +961,11 @@ class SingleSelectWidget(quixote.form.widget.SingleSelectWidget):
|
|||
self.options = [x[:3] for x in self.full_options]
|
||||
|
||||
def render_content(self):
|
||||
attrs = {'id': 'form_' + self.name}
|
||||
if self.required:
|
||||
attrs['aria-required'] = 'true'
|
||||
if self.attrs:
|
||||
attrs.update(self.attrs)
|
||||
tags = [htmltag("select", name=self.name, **self.attrs)]
|
||||
for object, description, key, attrs in self.full_options:
|
||||
if self.is_selected(object):
|
||||
|
|
Loading…
Reference in New Issue