[Zope] dtml-if and checkboxes
Jim Penny
jpenny@universal-fasteners.com
Fri, 4 Oct 2002 16:34:39 -0400
On Fri, Oct 04, 2002 at 04:15:01PM -0400, Hires, Russell (CAP, CARD) wrote:
> Hey All,
>
> I'm experimenting with zope again, playing with the REQUEST object and form
> objects. In my latest delimma, I've got the following snippet:
>
> <dtml-if expr="check_box == ('on')">
> The check box is checked!
> </dtml-if>
>
> What I don't get: if the checkbox is checked in the form, then this works,
> and I get the output. If it isn't checked, then I get an error saying that
> the checkbox ("check_box" in the form) isn't defined. This is borne out as
> well by <dtml-var expr="REQUEST.form">, which shows a text box's name and
> the value that it holds (whether it holds a value or not), and the
> checkbox's name and value ('on'), when it's checked. If it isn't checked, it
> isn't there at all. So, I guess I'm going to have to look to see whether
> it's there or not, right? How would I do that?
This is how HTML works. Rather bad design.
You want something like:
<dtml-if expr="REQUEST.has_key('check_box') and check_box == 'on'">
Checked!
</dtml-if>
Note that the second part is completely redundant.
<dtml-if expr="REQUEST.has_key('check_box')">
Checked!
</dtml-if>
Does the same thing.
In ZPT, this looks like
<span tal:condition="python:request.has_key('check_box')">Checked!</span>
Or, more probably
<input type="checkbox" name="check_box"
tal:attributes="checked request/check_box|nothing" />
Jim Penny
>
> Thanks for the help!
>
> Russell
>
> _______________________________________________
> 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 )
>