Re: [Zope] Multiple selection property as list
Alexander James Tucker writes:
.... In <dtml-if expr="'Some group' in groups"> "groups" is a string, in <dtml-in groups> it is a list .... I cannot believe this! Both "groups" are resolved in the same way.
Dieter
Actually if by "Multipel selection property" you mean checkboxes on a form, if you check only one, you get a string. If you check more than one, you get a list. This is what I do to detect that (but I'll bet someone knows a better way!) On my form I have 25 checkboxes with the name "takeaction", each with a different value. The ".len(takeaction[0])" gives me a 1 if the "takeaction" is a string, otherwise it gives me the length of the first value, which is never 1 in my case, otherwise this technique would not work. <dtml-if expr="_.len(takeaction[0])==1"> <dtml-call "REQUEST.set('takeaction',(takeaction,))"> </dtml-if> After this, the variable can be treated as a list even if it comes in as a string. Regards, JJ Dieter Maurer wrote:
Alexander James Tucker writes:
.... In <dtml-if expr="'Some group' in groups"> "groups" is a string, in <dtml-in groups> it is a list .... I cannot believe this! Both "groups" are resolved in the same way.
Dieter
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
If, on your form, you use something like this: <input type=radio name="takeaction:list"> Then the returned value will *always* be a list, no need then for your check. Phil ----- Original Message ----- From: "Joh Johannsen" <jojo@farm9.com> To: "Dieter Maurer" <dieter@handshake.de> Cc: "Alexander James Tucker" <alex.tucker@totalise.co.uk>; <zope@zope.org> Sent: Tuesday, March 13, 2001 11:06 PM Subject: Re: [Zope] Multiple selection property as list
Actually if by "Multipel selection property" you mean checkboxes on a form, if you check only one, you get a string. If you check more than one, you get a list.
This is what I do to detect that (but I'll bet someone knows a better way!)
On my form I have 25 checkboxes with the name "takeaction", each with a different value. The ".len(takeaction[0])" gives me a 1 if the "takeaction" is a string, otherwise it gives me the length of the first value, which is never 1 in my case, otherwise this technique would not work.
<dtml-if expr="_.len(takeaction[0])==1"> <dtml-call "REQUEST.set('takeaction',(takeaction,))"> </dtml-if>
After this, the variable can be treated as a list even if it comes in as a string.
Regards,
JJ
Dieter Maurer wrote:
Alexander James Tucker writes:
.... In <dtml-if expr="'Some group' in groups"> "groups" is a string, in <dtml-in groups> it is a list .... I cannot believe this! Both "groups" are resolved in the same way.
Dieter
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
thanks! I never knew what all these ":" things were all about Regards, JJ Phil Harris wrote:
If, on your form, you use something like this:
<input type=radio name="takeaction:list">
Then the returned value will *always* be a list, no need then for your check.
Phil
Joh Johannsen writes:
Actually if by "Multipel selection property" you mean checkboxes on a form, if you check only one, you get a string. If you check more than one, you get a list.
This is what I do to detect that (but I'll bet someone knows a better way!) .... There is an easier way:
append a ":list" suffix to your form variable name. This will ensure that you get a list, if at least one checkbox is checked. You will still get nothing, when none of the checkboxes is checked. You can use something like: <dtml-unless "REQUEST.form['my_checkbox']"> <dtml-call "REQUEST.form.update({'my_checkbox':()})"> </dtml-unless> to handle this case. More on issues like that in URL:http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html Dieter
Dieter Maurer wrote:
I cannot believe this! Both "groups" are resolved in the same way.
I finally traced the problem to the fact that the default value of the property (i.e. if it isn't set from the constructor form) is the empty string, not the empty list. Alex.
participants (4)
-
Alexander James Tucker -
Dieter Maurer -
Joh Johannsen -
Phil Harris