Forum OpenACS Q&A: checking multiple checkboxes... how? broekn?

I have an ad_form (on 4.6.2) that contains a checkbox that has multiple, uh boxes. It looks a little something like this:
set cboxes [list [list don 0] [list talli 1] [list daveb 2]]
ad_form ...
   {-section "Vote early, vote often!"}
   {cb_admin:text(checkbox),optional {options [list $cboxes]} {label \"Current Admins\"})
...
This renders as I would expect:
Vote early, vote often!
[ ] don  [ ] talli  [ ] daveb
But what I want to do is pre-check the boxes
set cboxes [list [list george 0] [list pat  1] [list al 2] ]
set values [list 0 1]
ad_form ...
   {-section "Your vote counts!"}
   {cb_admin:text(checkbox),optional {options [list $cboxes]} {label \"My favorites\"} {values [list $values])
...
And that renders as I would expect.
Your vote counts!
[x] george [x] pat [ ] al
But now, I want to set those multiple checks programatically:
set cboxes [list [list cut_taxes 0] [list abolish_civil_rights  1] [list strategerize 2] ]
set values [list 0 1]
ad_form -name todo...
   {-section "Dick Says I Should"}
   {tasks:text(checkbox),optional {options [list $cboxes]} {label \"My favorites\"} {values [list $values])
...
I want to check off the boxes programatically, so I try this:
template::element::set_value todo tasks [list 0 1 2]
Basically, I can't get set_value to work at all for multiple selected checkboxes. If you look at the code, it loves putting my arguments in an additional list.

If you peek into the arrays, you can see the result is that my values are nested too deeply into the list.

I believe

template::element::set_value todo tasks 0
would work.

But to set multiple values, I have to do this:

set todo:tasks(values) [list 0 1 2]
That works!

Can someone help out? Is this broekn or is there something else I should be doing?

Thanks!

So by the way, I hear some of you asking why I need to do this with template::element::set_value if the ad_form thingy works.

If I set the ad_form up as:

ad_form -name todo -form {
    {tasks:text(checkbox),optional {options [list $cboxes]} {label \"My favorites\"} {values [list $values])
} -new_data {

    ns_log notice tasks: [template::element::get_value todo tasks]
    
}
Then what comes out of template::element::get_value is not what the user checked on the form, but is in fact what I had stuck into the form in the initial definition. (At least, that's what I recall from a few hours back...)
Collapse
Posted by Jade Rubick on
Jerry, I'm afraid I haven't done exactly what you're doing yet. However, I should be working on something similar today and tomorrow. I'll let you know if I figure anything out. If you're on IRC, remind me, okay? We can then post it here.
Collapse
Posted by Andrew Spencer on
Hi Jerry. I believe I ran into something like this a while back. You can use ad_form as you think, just make sure to check for submissions in the tcl code, and don't set the checkboxes if it's a submission.