[Zope-CMF] Checkbox...

J Cameron Cooper jccooper at jcameroncooper.com
Tue Feb 3 20:18:53 EST 2004


ramon.aseniero at tryarc.com wrote:

> I am having a hard time rendering values on a checkbox – like I want 
> to display a check on the checkbox if the value is true and no check 
> if false.
>
> Also, when I change the value on the checkbox it does not seem to 
> affect the value of the field in the database. Below is my code.
>
> <p tal:define="accessToMentorArea member/accessToMentorArea"><font 
> size="-1" face="Arial, Helvetica, sans-serif">
>
> <span tal:condition="accessToMentorArea" tal:omit-tag="">
>
> <input type="checkbox" name="accessToMentorArea" value="1" 
> checked="checked">
>
> </span>
>
> <span tal:condition="not:accessToMentorArea" tal:omit-tag="">
>
> <input type="checkbox" name="accessToMentorArea" value="0">
>
> </span>
>
> Allow this Member to access all Mentor areas</font> </p>
>
Recall that in HTML forms that nothing will be sent for a non-checked 
checkbox. You must check in whatever method this submits to for the 
existence of that request parameter to decide if it is negative (or 
provide a default on method parameters, if you're using a Python script 
or a ZSQL method or something similar.)

I use this scheme to make things conditionally selected::

<input type="checkbox" name="accessToMentorArea" value="1" 
tal:attributes="checked accessToMentorArea | nothing">

--jcc

-- 
"Code generators follow the 80/20 rule. They solve most of the problems, but not all of the problems. There are always features and edge cases that will need hand-coding. Even if code generation could build 100 percent of the application, there will still be an endless supply of boring meetings about feature design."
(http://www.devx.com/java/editorial/15511)




More information about the Zope-CMF mailing list