Commit a89afa43 authored by Vincent Pelletier's avatar Vincent Pelletier

Formulator: Support disabled items in all ItemWidget subclasses.

parent 2e139aec
...@@ -775,6 +775,17 @@ class ItemsWidget(Widget): ...@@ -775,6 +775,17 @@ class ItemsWidget(Widget):
default="", default="",
required=0) required=0)
@staticmethod
def render_element(tag, **kw):
"""
Similar to global render_element, but render None values as disabled
elements.
"""
if kw['value'] is None:
kw.pop('value')
kw['disabled'] = None
return render_element(tag, **kw)
class SingleItemsWidget(ItemsWidget): class SingleItemsWidget(ItemsWidget):
"""A widget with a number of items that has only a single """A widget with a number of items that has only a single
selectable item. selectable item.
...@@ -1119,14 +1130,11 @@ class ListWidget(SingleItemsWidget): ...@@ -1119,14 +1130,11 @@ class ListWidget(SingleItemsWidget):
return "\n".join([list_widget, input_hidden]) return "\n".join([list_widget, input_hidden])
def render_item(self, text, value, key, css_class, extra_item): def render_item(self, text, value, key, css_class, extra_item):
if value is None: return self.render_element('option', contents=text, value=value,
return render_element('option', contents=text, disabled=None,
extra=extra_item)
return render_element('option', contents=text, value=value,
extra=extra_item) extra=extra_item)
def render_selected_item(self, text, value, key, css_class, extra_item): def render_selected_item(self, text, value, key, css_class, extra_item):
return render_element('option', contents=text, value=value, return self.render_element('option', contents=text, value=value,
selected=None, extra=extra_item) selected=None, extra=extra_item)
ListWidgetInstance = ListWidget() ListWidgetInstance = ListWidget()
...@@ -1161,14 +1169,11 @@ class MultiListWidget(MultiItemsWidget): ...@@ -1161,14 +1169,11 @@ class MultiListWidget(MultiItemsWidget):
return "\n".join([multi_list,input_hidden]) return "\n".join([multi_list,input_hidden])
def render_item(self, text, value, key, css_class, extra_item): def render_item(self, text, value, key, css_class, extra_item):
if value is None: return self.render_element('option', contents=text, value=value,
return render_element('option', contents=text, disabled=None,
extra=extra_item)
return render_element('option', contents=text, value=value,
extra=extra_item) extra=extra_item)
def render_selected_item(self, text, value, key, css_class, extra_item): def render_selected_item(self, text, value, key, css_class, extra_item):
return render_element('option', contents=text, value=value, return self.render_element('option', contents=text, value=value,
selected=None, extra=extra_item) selected=None, extra=extra_item)
MultiListWidgetInstance = MultiListWidget() MultiListWidgetInstance = MultiListWidget()
...@@ -1202,7 +1207,7 @@ class RadioWidget(SingleItemsWidget): ...@@ -1202,7 +1207,7 @@ class RadioWidget(SingleItemsWidget):
return string.join(rendered_items, "<br />") return string.join(rendered_items, "<br />")
def render_item(self, text, value, key, css_class, extra_item): def render_item(self, text, value, key, css_class, extra_item):
return render_element('input', return self.render_element('input',
type="radio", type="radio",
css_class=css_class, css_class=css_class,
name=key, name=key,
...@@ -1210,7 +1215,7 @@ class RadioWidget(SingleItemsWidget): ...@@ -1210,7 +1215,7 @@ class RadioWidget(SingleItemsWidget):
extra=extra_item) + text extra=extra_item) + text
def render_selected_item(self, text, value, key, css_class, extra_item): def render_selected_item(self, text, value, key, css_class, extra_item):
return render_element('input', return self.render_element('input',
type="radio", type="radio",
css_class=css_class, css_class=css_class,
name=key, name=key,
...@@ -1247,7 +1252,7 @@ class MultiCheckBoxWidget(MultiItemsWidget): ...@@ -1247,7 +1252,7 @@ class MultiCheckBoxWidget(MultiItemsWidget):
return string.join(rendered_items, "<br />") return string.join(rendered_items, "<br />")
def render_item(self, text, value, key, css_class, extra_item): def render_item(self, text, value, key, css_class, extra_item):
return render_element('input', return self.render_element('input',
type="checkbox", type="checkbox",
css_class=css_class, css_class=css_class,
name=key, name=key,
...@@ -1255,7 +1260,7 @@ class MultiCheckBoxWidget(MultiItemsWidget): ...@@ -1255,7 +1260,7 @@ class MultiCheckBoxWidget(MultiItemsWidget):
extra=extra_item) + text extra=extra_item) + text
def render_selected_item(self, text, value, key, css_class, extra_item): def render_selected_item(self, text, value, key, css_class, extra_item):
return render_element('input', return self.render_element('input',
type="checkbox", type="checkbox",
css_class=css_class, css_class=css_class,
name=key, name=key,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment