Forum OpenACS Q&A: Creating checkboxes with db_multirow

I am trying to create a list of items with corresponding checkboxes. The list is queried using db_multirow:
element create delete_subscription subscription_id \
 -label "" -datatype text -widget checkbox -options ""

db_multirow subscriptions subscriptions { *SQL* } {
    template::widget::checkbox subscription_id tag_attributes
}
Here I create the checkbox and then append options with template::widget::checkbox subscription_id tag_attributes.

I now have two questions.

Firstly, as you can see, I haven't specified tag_attributes in the code snippet - simply because I am not sure how to. I've tried the standard "{{Pretty_Name name}}" used with element create -widget checkbox, but it gives me errors. Does anyone know the right way of specifying tag_attributes?

Secondly, is there are a better way of doing this or am I on the right track?

/Simon

Collapse
Posted by Dave Bauer on
try
element create delete_subscription subscription_id \
 -label "" -datatype text -widget checkbox -options [db_list_of_lists queryname {*SQL*}]
with a query that will return the info in the proper format.
Collapse
Posted by Jon Griffin on
You really should use ad_form, http://jongriffin.com/static/openacs/ad_form/using-ad-form, will tell you how.
Collapse
Posted by Tilmann Singer on
If you need to create the multirow also for something else then you might put together a list in its code block and use that later for setting the options list:

set options [list]
db_multirow subscriptions subscriptions { *SQL* } {
  lappend options [list $caption $value]
}

element create delete_subscription subscription_id \
  -label "" -datatype text -widget checkbox        \
  -options $options

Jon - I don't see any advantage of using ad_form over the old way in this particular case except the general reasons for ad_form - did you mean those or is this problem easier to solve with ad_form, if yes how?
Collapse
Posted by Jon Griffin on
My main reason was for the advantages and the reality is that the new consensus seems to be using ad_form.

You are right that it doesn't make the problem easier per se ( although I would argue that it is more readable).