Forum OpenACS Development: How do I add a new switch to formbuilder and ad_form?

Hello,

(This question is about OpenACS 5.2.3.)

I'd like to add another parameter/value pair (called "pos-group", similar to "section" to some form elements, to allow me to alter display on some elements. (I thought it made more sense to do this than create a whole pile of new widgets, but maybe I was wrong.) I set out to essentially duplicate the code in the templating system that handles sections.

So I changed:
acs-templating-init.tcl to add a default value for pos-group.

In template::element::create, I added
set opts(pos-group) $form_properties(pos-group)
to duplicate what I saw for section. However, when I added some ns_logging, I got blank values for both $form_properties(section) and $form_properties(pos-group), even when I had a section set (and displaying properly in the form).

I duplicated template::form::section to make template::form::pos-group, but the ns_log statement I have in both template::form::section and template::form::pos-group doesn't seem to be appearing.

I looked at ad_form but didn't see anything specific to the -section flag there, so I didn't make any changes. (I did see:

foreach element $form {
set element_name_part [lindex $element 0]
# This can easily be generalized if we add more embeddable form commands ...

if { [string equal $element_name_part "-section"] } {
lappend af_element_names($form_name) "[list "-section" [uplevel [list subst [lindex $element 1]]]]"
ns_log notice "CAS found a section!"
} else {
set element_name_part [uplevel [list subst $element_name_part]]

..but I don't think this is the same "section", as I never saw the first part get invoked when I added some ns_log statements.

I've reloaded, I've watched files, I've restarted the server, but I'm stumped. Setting a section works just fine in practice, and yet I can't see it getting set in my ns_log statements, which makes me wonder if I'm totally missing some proc where the work actually gets done.

Any pointers?

Thanks!

Collapse
Posted by Dave Bauer on
I am not sure what this is supposed to do but you can add arbitrary properties to any widget.

That is

ad_form -name myform -form {
    {mywidget:text -pos_group {...}}
}

Will magically create the property available within the
template::widget::text
tcl procedure.

You can get to it by referring to the property in the element array:

    upvar $element_reference element

    if { ! [info exists element(pos_group)] } {
        ... do something
    }
Ah-ha. Apparently having a hyphen in the name was a baad idea. Now that I'm using pos_group, everything is working OK. Sorry for the spammage. :)
Collapse
Posted by Dave Bauer on
AH yeah my example is wrong too.

ad_form -name myform -form {

    {mywidget:text {pos_group {...}}

}

Is correct.