Forum OpenACS Development: Ad_form: assigning multiple values to checkbox element

Request notifications

Hi there,

How to assign multiple values to an ad_form element -> integer(checkbox) - multiple choices, using TCL script?

More specifically, the ad_form chunk is presented bellow.

ad_form -extend -name annonce -form {
{category_$i:integer(checkbox),optional
{label "<h3>$tree_name</h3>"}
{options $category_options}
The data is inserted in the database as varchar datatype, as in: "1908 1914 1915 1918" .

After retrieving the data, (i.e. "1908 1914 1915 1918") in the -edit_request {} block, I need to assign those ids to each to the checkbox widgets in order to display them as checked.

Briefly, I need to assign multiple values to the checkbox widget. The ad_form element has 10 options and I need to check only the ones retrieved from the DB.

db_1row select_annonce {
SELECT

a.category_1
EX: The content of category_1 is « 1908 1914 1915 1918 »

I searched for references within OACS source, but I found no such example.

Does anybody have enlightening idea, or another approach, for programming such solution using TCL script?

p.s. I'd like to accomplish "re-using" TCL and ad_form structures, instead of creating a Javascript chunk. Is it possible?

Best wishes,

Collapse
Posted by Dave Bauer on
In the edit request you need to set the variable for category_$i to a list so something like

set category_$i [split $database_value] since it looks like the database value is a space separated string.

Collapse
Posted by Iuri Sampaio on
Dave,

I've tried that before. So far, It works only when only one id (i.e. option) is selected previously or it assigns and checks the last value only

I've tested it specifically to 1 in order to get the chunk correct then I generalized to all, as in $i, but It doesn't work.

Best wishes,
Iuri

I've done that in the past but somehow It doesn't work anymore :)

Collapse
Posted by Iuri Sampaio on
Furthermore,
I tried another approach as bellow, but nothing yet.

Ex. "{1701} {1094} {1672} {1741}"

Collapse
Posted by Benjamin Brink on
Hi Iuri,

Regarding "..another approach, for programming such solution using TCL script?"

Q-forms has qf_choices, but it expects the whole form to be generated starting with qf_form..

cheers,
Ben

Collapse
Posted by Iuri Sampaio on
Thanks Ben,
I'm starting to recreate the form right now.
Best wishes,
Iuri