[Checkins] SVN: z3c.form/trunk/ Added prompt in select widget and
updated interface.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Fri Jun 29 00:30:09 EDT 2007
Log message for revision 77206:
Added prompt in select widget and updated interface.
Changed:
U z3c.form/trunk/CHANGES.txt
U z3c.form/trunk/src/z3c/form/browser/select.py
U z3c.form/trunk/src/z3c/form/browser/select.txt
U z3c.form/trunk/src/z3c/form/interfaces.py
-=-
Modified: z3c.form/trunk/CHANGES.txt
===================================================================
--- z3c.form/trunk/CHANGES.txt 2007-06-29 04:21:02 UTC (rev 77205)
+++ z3c.form/trunk/CHANGES.txt 2007-06-29 04:30:09 UTC (rev 77206)
@@ -5,6 +5,11 @@
Version 1.4.0 (??/??/2007)
-------------------------
+- Feature: The select widget grew a new ``prompt`` flag, which allows you to
+ explicitely request a selection prompt as the first option in the selection
+ (even for required fields). When set, the prompt message is shown. Such a
+ prompt as option is common in Web-UIs.
+
- Feature: Allow "no value message" of select widgets to be dynamilcally
changed using an attribute value adapter.
@@ -24,7 +29,9 @@
-- can now be specified either as the "actionFactory" on the button field or
as an adapter.
+- Bug: Recorded all public select-widget attributes in the interface.
+
Version 1.3.0 (6/22/2007)
-------------------------
Modified: z3c.form/trunk/src/z3c/form/browser/select.py
===================================================================
--- z3c.form/trunk/src/z3c/form/browser/select.py 2007-06-29 04:21:02 UTC (rev 77205)
+++ z3c.form/trunk/src/z3c/form/browser/select.py 2007-06-29 04:30:09 UTC (rev 77206)
@@ -35,12 +35,14 @@
size = 1
multiple = None
items = ()
+ prompt = False
noValueMessage = _('no value')
+ promptMessage = _('select a value ...')
# Internal attributes
_adapterValueAttributes = widget.SequenceWidget._adapterValueAttributes + \
- ('noValueMessage',)
+ ('noValueMessage', 'promptMessage')
def isSelected(self, term):
return term.token in self.value
@@ -49,11 +51,14 @@
"""See z3c.form.interfaces.IWidget."""
super(SelectWidget, self).update()
self.items = []
- if not self.required and self.multiple is None:
+ if (not self.required or self.prompt) and self.multiple is None:
+ message = self.noValueMessage
+ if self.prompt:
+ message = self.promptMessage
self.items.append({
'id': self.id + '-novalue',
'value': self.noValueToken,
- 'content': self.noValueMessage,
+ 'content': message,
'selected': self.value == []
})
for count, term in enumerate(self.terms):
Modified: z3c.form/trunk/src/z3c/form/browser/select.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/browser/select.txt 2007-06-29 04:21:02 UTC (rev 77205)
+++ z3c.form/trunk/src/z3c/form/browser/select.txt 2007-06-29 04:30:09 UTC (rev 77206)
@@ -129,6 +129,10 @@
>>> widget.extract(default=1)
1
+
+Custom No Value Messages
+------------------------
+
Additionally to the standard dynamic attribute values, the select widget also
allows dynamic values for the "no value message". Initially, we have the
default message:
@@ -150,3 +154,61 @@
>>> widget.update()
>>> widget.noValueMessage
u'- nothing -'
+
+
+Explicit Selection Prompt
+-------------------------
+
+In certain scenarios it is desirable to ask the user to select a value and
+display it as the first choice, such as "please select a value". In those
+cases you just have to set the ``prompt`` attribute to ``True``:
+
+ >>> widget.prompt = True
+ >>> widget.update()
+ >>> print widget.render()
+ <select id="widget-id" name="widget.name:list"
+ class="selectWidget" size="1">
+ <option id="widget-id-novalue" value="--NOVALUE--"
+ selected="selected">select a value ...</option>
+ <option id="widget-id-0" value="a">a</option>
+ <option id="widget-id-1" value="b">b</option>
+ <option id="widget-id-2" value="c">c</option>
+ </select>
+ <input name="widget.name-empty-marker" type="hidden"
+ value="1" />
+
+As you can see, even though the field is not required, only the explicit
+prompt is shown. However, the prompt will also be shown if the field is
+required:
+
+ >>> widget.required = True
+ >>> widget.update()
+ >>> print widget.render()
+ <select id="widget-id" name="widget.name:list"
+ class="selectWidget" size="1">
+ <option id="widget-id-novalue" value="--NOVALUE--"
+ selected="selected">select a value ...</option>
+ <option id="widget-id-0" value="a">a</option>
+ <option id="widget-id-1" value="b">b</option>
+ <option id="widget-id-2" value="c">c</option>
+ </select>
+ <input name="widget.name-empty-marker" type="hidden"
+ value="1" />
+
+Since the prompy uses the "no value" as the value for the selection, all
+behavior is identical to selecting "no value". As for the no-value message,
+the prompt message, which is available under
+
+ >>> widget.promptMessage
+ u'select a value ...'
+
+can also be changed using an attribute value adapter:
+
+ >>> PromptMessage = StaticWidgetAttribute(u'please select a value')
+ >>> zope.component.provideAdapter(PromptMessage, name='promptMessage')
+
+So after updating the widget you have the custom value:
+
+ >>> widget.update()
+ >>> widget.promptMessage
+ u'please select a value'
Modified: z3c.form/trunk/src/z3c/form/interfaces.py
===================================================================
--- z3c.form/trunk/src/z3c/form/interfaces.py 2007-06-29 04:21:02 UTC (rev 77205)
+++ z3c.form/trunk/src/z3c/form/interfaces.py 2007-06-29 04:30:09 UTC (rev 77206)
@@ -352,6 +352,39 @@
class ISelectWidget(ISequenceWidget):
"""Select widget with ITerms option."""
+ size = zope.schema.Int(
+ title=_('Size'),
+ description=_('Determines how many options are shown at once.'),
+ default=1)
+
+ multiple = zope.schema.Bool(
+ title=_('Multiple'),
+ description=_('A flag, when set, allows for multiple values to be '
+ 'selected.'),
+ default=False)
+
+ prompt = zope.schema.Bool(
+ title=_('Prompt'),
+ description=_('A flag, when set, enables a choice explicitely '
+ 'requesting the user to choose a value.'),
+ default=False)
+
+ items = zope.schema.Tuple(
+ title=_('Items'),
+ description=_('A collection of dictionaries containing all pieces of '
+ 'information for renderiing. The following keys must '
+ 'be in each dictionary: id, value, content, selected'))
+
+ noValueMessage = zope.schema.Text(
+ title=_('No-Value Message'),
+ description=_('A human-readable text that is displayed to refer the '
+ 'missing value.'))
+
+ promptMessage = zope.schema.Text(
+ title=_('Prompt Message'),
+ description=_('A human-readable text that is displayed to refer the '
+ 'missing value.'))
+
class IOrderedSelectWidget(ISequenceWidget):
"""Ordered Select widget with ITerms option."""
More information about the Checkins
mailing list