[Zope] Multiple selections

Jim Washington jwashin@vt.edu
Fri, 10 Dec 1999 16:20:51 +0000


Hi, Alexander

A tougher answer than first anticipated.  Here's how to do it, but first
a work-around for a bug (it's not a feature, is it?) I am seeing in Zope
2.1.  I see something like this bug in the collector called "Zope Bug:
Can't add multiple selection property", so I will not submit a new one. 
Perhaps the work-around will provide some clues for swatting the bug as
well...

The following examples relate how multiple selections should work,
though you might get get 
  Error Type: TypeError
  Error Value: string member test needs char left operand
when you add a multiple select object.  Don't panic.  You have not done
anything wrong.

The workaround until this is fixed seems to be to make your initial list
with *one character per item*, then select one or more things after
creating the multiple selection object, save it, then change the initial
list to what you need, *while leaving something selected in the multiple
selection*. After you have saved this, you can change your selections. 
YMMV.  It works for me; using multiple selection objects might be more
trouble than they are worth for the moment.

Now, with that in mind, I will answer the questions:

A.  If you want a property of your folder or document that returns a
subset of a pre-existing list (the proper use for multiple select
objects):

First, create the list.  

1.  Create a property of type "lines" or "tokens", naming it
"selectionchoices", for example.  
2.  Add.
3.  Enter the values you want into the list.  Note the bug workaround
above, which means one-character values for the moment.
4.  Save Changes.

Now, make a subset.

1.  Go to where you want only a *subset* of that list to be used. This
may be anywhere on the acquisition path from the list, but usually on
the same property page.  
2.  Create a property of type "multiple selection".  
3.  Name it whatever you want. I will call it "selectionsubset"
4.  Set the value to the name of the list of choices, in this case,
selectionchoices.  
5.  Add.

Now, mySelections is displayed on your properties page, and the manager
can select some subset of the choices, and using <dtml-in
selectionsubset> a dtml method or document can use the list of selected
things.


B.  But if you just want to *display* a multiple-selection list, you
need to do something else.  For a more thorough recitation of this, go
to AlexR's page about selections:
http://www.zope.org/Members/AlexR/SelectionLists

1.  If you want just to display a list for multiple selection:

You may use a full list, like "selectionchoices" or a partial list, like
"selectionsubset", or a python list e.g., "['choice a', 'choice b']" but
then you need to do the HTML/DTML thing.  Note these have to be within a
<form></form> to display properly.

For example, 
           
<select name="myselect:list" multiple>
<dtml-in selectionchoices>               
 <option><dtml-var sequence-item></option>
</dtml-in>
</select>

2.  If you want to display something identical to your multiple select
on the property form:

<select name="myselect:list" multiple>
<dtml-in selectionchoices>
  <dtml-let theitem=sequence-item>
  <option <dtml-if "theitem in selectionsubset"> 
           SELECTED 
          </dtml-if>>
  <dtml-var theitem>
  </option>
  </dtml-let>
</dtml-in>
</select>

Hope this helps.

-- Jim Washington

Alexander Limi wrote:
> 
> Zopistas,
> 
> Can anybody give me an example of how to use multiple selections? (the data
> type, that is). I searched all my Zope docs, and it was only mentioned one
> place in the Zope quick reference, but no usage examples.
> 
> Where does it get its possible selections from? And will it be rendered as a
> multiple selection field?
> 
> Thanks in advance.
> 
> Alexander Limi
> http://mp3.no