[Plone-Users] SelectionWidget bug?: first value selected automatically

43 views
Skip to first unread message

Harald Friessnegger

unread,
May 18, 2009, 11:38:36 AM5/18/09
to plone...@lists.sourceforge.net
When i define a StringField with an optional value using a SelectionWidget i
get two different behaviours depending on the type of selectionwidget i
use::

atapi.StringField('floor',
required = False,
vocabulary = ['one','two','three']
widget = atapi.SelectionWidget(
label = _(u"Floor"),
type = 'radio',
),
)


for type=='radio' i get five options, no option is chosen. submitting the
form w/o touching the widget will result in context.floor == ''::

[] one
[] two
[] three


for type=='select' i get a pulldown with 'one' pre-selected. submitting the
form w/o touching this widget results in context.floor=='one'


To use a pulldown w/o having 'one' set by default i'd need to define

vocabulary = ['','one','two','three']

which would result in a useless selectable value in case we switch back to
type=='radio'


Is there a _good_ reason archetype's selectionwidget does not automatically
add an empty choice if required==False and type=='select'???

How did other people work around this problem (i'm sure i'm not the first
one struggling with this)?


regards, fRiSi

--
Webmeisterei GmbH - Büro für Netzfragen
Tel: +43 5572 908877, Fax: +43 5572 908877-66
Steinebach 18, A-6850 Dornbirn
http://www.webmeisterei.com


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables
unlimited royalty-free distribution of the report engine
for externally facing server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Plone-Users mailing list
Plone...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/plone-users

Raphael Ritz

unread,
May 19, 2009, 3:02:25 AM5/19/09
to plone...@lists.sourceforge.net
Harald Friessnegger wrote:
> When i define a StringField with an optional value using a SelectionWidget i
> get two different behaviours depending on the type of selectionwidget i
> use::

I'd call it a bug.

In ATExtensions I work around this by having an optional
argument to 'getDisplayList' (defined in there) which I
use as a basis for controlled vocabularies managed in ZMI
to add the empty entry in front if needed.

Raphael

>
> atapi.StringField('floor',
> required = False,
> vocabulary = ['one','two','three']
> widget = atapi.SelectionWidget(
> label = _(u"Floor"),
> type = 'radio',
> ),
> )
>
>
> for type=='radio' i get five options, no option is chosen. submitting the
> form w/o touching the widget will result in context.floor == ''::
>
> [] one
> [] two
> [] three
>
>
> for type=='select' i get a pulldown with 'one' pre-selected. submitting the
> form w/o touching this widget results in context.floor=='one'
>
>
> To use a pulldown w/o having 'one' set by default i'd need to define
>
> vocabulary = ['','one','two','three']
>
> which would result in a useless selectable value in case we switch back to
> type=='radio'
>
>
> Is there a _good_ reason archetype's selectionwidget does not automatically
> add an empty choice if required==False and type=='select'???
>
> How did other people work around this problem (i'm sure i'm not the first
> one struggling with this)?
>
>
> regards, fRiSi
>

Harald Friessnegger

unread,
May 20, 2009, 10:24:55 AM5/20/09
to plone...@lists.sourceforge.net
thx raphael.

i submitted a bug (https://dev.plone.org/plone/ticket/9212) and will stick
with the


vocabulary = ['','one','two','three']

solution in the meantime..

regards, fRiSi


Raphael Ritz wrote:

--

Webmeisterei GmbH - Büro für Netzfragen
Tel: +43 5572 908877, Fax: +43 5572 908877-66
Steinebach 18, A-6850 Dornbirn
http://www.webmeisterei.com

Reply all
Reply to author
Forward
0 new messages