Forum OpenACS Development: Retrieving ",multiple" from ad_form in widget proc

I was wondering if there is any way in the widget creation proc (e.g. template::widget::menu) to know if ",multiple" was specified in the element creation.

I tried to find it in the element array, but only ",optional" is resolved in the element array with "optional 1", not ",multiple".

Is this on purpose, is this a bug, did I just not find where to look, you name it..

It would be really helpful if someone could point me where to investigate, as I don't want to write a multiselect widget for im_categories. And the hack used in categories to achieve this (passing the multiple as a custom parameter) is just that, a hack.

Thanks a bunch in advance for any pointers.

P.S.: Not urgent, I implemented the workaround using a custom parameter for the widget, still not really elegant, isn't it ?

Collapse
Posted by Dave Bauer on
Multiple is ad_form only. It is not an option to template::element::create.

The multiple flag basically tells if you use get_value or get_values in the internal ad_form code.

Luckily template::element::create takes an arbitraty set of arguments -name value and adds them to the element definition. In this way you can create widgets that accept any arbitrary parameters.

To fix this you'd need to pass the multiple designation through to template::element create.

Based on this simple analysis it seems reasonble, but I haven't reviewed if it would affect any existing widgets to have the extra parameter. I think it would be ignored as long as no widgets are not expecting a multiple flag for some other reason.

Collapse
Posted by Malte Sussdorff on
Hi Dave, thanks a lot for the explanation. I managed to get this done by only changing a single line:

Index: acs-tcl/tcl/form-processing-procs.tcl
===================================================================
--- acs-tcl/tcl/form-processing-procs.tcl (revision 462)
+++ acs-tcl/tcl/form-processing-procs.tcl (working copy)
@@ -809,6 +809,7 @@
if { $af_element_parameters($element_name:$flag) ne "" } {
return -code error "element $element_name: $flag attribute can not have a parameter"
}
+ lappend form_command "-$flag"
}

nospell -

It would be great to see this added to the toolkit, especially as we could get away with a lot of code that tries to figure out if something is multiple or not in the widget-procs.tcl But who knows, maybe there is some code written somewhere that relies on multiple not being set in the element create, so I leave this to the OCT to decide whether to pick it up or not.

Thanks again for the outline and hints.