Permalink
Browse files

Add a display widget for generic collections.

  • Loading branch information...
1 parent 796f564 commit 42cb5028076e87956d7a7ba28c9c8d600f86dabc @thefunny42 committed Aug 12, 2010
View
@@ -119,15 +119,15 @@ Currently supported fields:
- Date, Datetime: generate a text line input and parse/display the
date using the locale,
-- TextLine, Text, and numbers (Int, Float ...),
+- TextLine, Text, Boolean, URI, and numbers (Int, Float ...),
- Password,
-- Choice: generate a select,
+- Choice: generate a select or a radio boxes (widget mode ``radio``),
- Object,
-- Collections: List, Set, Tuple:
+- Collections: List, Set, Tuple in input and display mode:
- Collection of choices: generate a widget with a list of checkboxes,
@@ -83,17 +83,17 @@ def extract(self):
return (value, error)
-# Radio Widget
-
-class RadioFieldWidget(ChoiceFieldWidget):
- grok.adapts(ChoiceSchemaField, Interface, Interface)
- grok.name('radio')
-
- def renderableChoices(self):
- current = self.inputValue()
- base_id = self.htmlId()
- for choice in self.choices():
- yield {'token': choice.token,
- 'title': choice.title or choice.token,
- 'checked': choice.token == current and 'checked' or None,
- 'id': base_id + '-' + choice.token.replace('.', '-')}
+# Radio Widget
+
+class RadioFieldWidget(ChoiceFieldWidget):
+ grok.adapts(ChoiceSchemaField, Interface, Interface)
+ grok.name('radio')
+
+ def renderableChoices(self):
+ current = self.inputValue()
+ base_id = self.htmlId()
+ for choice in self.choices():
+ yield {'token': choice.token,
+ 'title': choice.title or choice.token,
+ 'checked': choice.token == current and 'checked' or None,
+ 'id': base_id + '-' + choice.token.replace('.', '-')}
@@ -117,10 +117,10 @@ def prepareContentValue(self, values):
for position, value in enumerate(values):
# Create new widgets for each value
self.newValueWidget(position, value)
- value_count = len(values)
- if not value_count:
+ count = len(values)
+ if not count:
self.allowRemove = False
- return {self.identifier: str(value_count)}
+ return {self.identifier: str(count)}
def prepareRequestValue(self, values):
value_count = 0
@@ -148,6 +148,12 @@ def update(self):
super(MultiGenericFieldWidget, self).update()
self.valueWidgets.update()
+
+
+class MultiGenericDisplayFieldWidget(MultiGenericFieldWidget):
+ grok.name('display')
+
+
# For collection of objects, generate a different widget (with a table)
class MultiObjectFieldWidget(MultiGenericFieldWidget):
@@ -0,0 +1,10 @@
+<tal:multi i18n:domain="zeam-form">
+ <tal:values tal:repeat="valueWidget widget.valueWidgets">
+ <tal:widget tal:replace="structure valueWidget.render()" />
+ <br />
+ </tal:values>
+ <p tal:condition="not:widget.valueWidgets"
+ i18n:translate="">
+ There are no values
+ </p>
+</tal:multi>

0 comments on commit 42cb502

Please sign in to comment.