[Zope-dev] [Mini-HowTo]: Multiple Selects in ZClass Edit Forms

Michael R. Bernstein webmaven@lvcm.com
Sat, 31 Mar 2001 00:59:50 -0800


Problem:
-------

You want your ZClass instance edit form to correctly display
the currently selected values for a multiple selection
property.

Assumptions:
-----------
You have a ZClass that has a multiple select property named
'format' with a value set to 'format_list'.

You have a 'format_list' lines property set where the ZClass
*instances* can acquire it.

You generated an 'Edit' type 'Property Sheet Interface' that
contains the following code:

  <tr><th align=left valign=top>format</th>
      <td align=left valign=top></td>
  </tr>

Solution:
--------
Replace the above code with the following:

  <tr><th align=left valign=top>format</th>
      <td align=left valign=top>
        <select name="format:list" multiple size="4">
          <dtml-in format_list>
          <option
          <dtml-if "_['sequence-item'] in _['format']">
          SELECTED</dtml-if> >
          <dtml-var sequence-item></option>
          </dtml-in>
        </select>
      </td>
  </tr>

This will correctly display the currently selected values
for your ZClass instance in the edit form, and capture the
changed values when the form is submitted, casting even
single selections to a list.

Note: If the 'format_list' lines property is set where the
Zclass instances can acquire it, but not where the ZClass
definition can acquire it, then the Property Sheet
management screen will *not* display the values. If you want
to provide a default set of values that the ZClass
definition can acquire as well as the ZClass instances (of
course you can also override this locally), set the
format_list property on the root folder.

HTH,

Michael Bernstein.