[Zope] Retrieving ans processing multiple list selections

Thomas B. Passin tpassin@mitretek.org
Mon, 25 Jun 2001 17:24:52 -0400


First you have to decide what should happen if there are multiple
selections.  Should only one of them display, or should all of them display?
I will assume that you want to display a list.

Simple iterate through all the selected options using <dtml-in>.  The value
of the option on each iteration is given by the sequence-item variable.

There are two caviats.  First, if only one option were selected, the
returned value would not be a list and this method would cause an error.
You can prevent this in the form by assigning the select element's name to
be "country:list".  Then you will be sure of getting a list even if only one
item has been selected.

Second, you may have to get a little fancy in how you refer to the variable
"sequence-item".  For example, this is fine:

<dtml-in "REQUEST['country']
    <dtml-sequence-item>
</dtml-in>

But if you are going to use "sequence-item" inside an expression, then it
won't work.  An expression would have to be inside quotation marks. Inside
quotes, everything is passed to Python to evaluate, and Python would try to
subtract a variable named "item" from one named "sequence", which wouldn't
work.  So there is an alternative way to refer to our variable.

"sequence-item" belongs to the namespace called "_".  That's a strange name,
but it means the current namespace - the dictionary of names immediately
accessible to the page. You need to ask for the value by name - that is, a
string - which would be 'sequence-item'.  This method lets you use a string
to specify your variable, and so you avoid the problem mentioned above.

 You use it like this:

<dtml-var "_['sequence-item']">

Cheers,

Tom P

[Sabine Ritter]
I am using a form with several drop-down lists which allow multiple options
to be selected.
example:
    <select name="country"  size="8" multiple>
     <option selected value="">entire Europe
     <option value="1">France
     <option value="2">Germany
     .....................
     <option value="15">Denmark
     <option value="16">Spain
    </select>

The selections are used in an ZSQL-Method:

SELECT x, y, COUNT(lfdnr) AS Anzahl
FROM table
<dtml-sqlgroup where>
  <dtml-sqltest country type=int multiple optional>
<dtml-and>
....................
</dtml-sqlgroup>
GROUP BY x, y, z

The result of the ZSQL-Method is shown on a report page with
<dtml-in ZSQL-Method size=50 start=query_start>
......................

Before displaying the result of the query I would like to summarize the
selection like:
"You have selected:
country: France and Denmark
age-group: 10-14 years and 15-19 years
-----
Here is the result of your query:
<table>

As long as only one option is selected is can use
<dtml-if expr="country=='1'">
  France
<dtml-elif expr="country=='2'">
  Germany
....................

However, if multiple options are selected, <dtml-var bl> will return a list
of values
like ['3','4','6'] and the above 'translation' doesn't work any more.

Q u e s t i o n:
How can I process ('translate') the list-values?
Is there a way to directly adress the option text???