Forum OpenACS Q&A: Re: Using multiple hidden vars with template::element::create

Collapse
Posted by Brian Fenton on
I modified the hidden widget as follows. Wasn't too sure what to do about the id tag. The "values" attribute should be a list of values.
ad_proc -public template::widget::hidden {
    element_reference
    tag_attributes
} {

    @param element_reference Reference variable to the form element
    @param tag_attributes HTML attributes to add to the tag

    @return Form HTML for widget
} {

    upvar $element_reference element

    if { [exists_and_not_null element(values)] } {
      set values $element(values)
      set output {}
      foreach value $values {
        set value [ad_quotehtml $value]
        append output "<input type=\"hidden\" id=\"$element(name)\" name=\"$element(name)\" value=\"$value\">\n"
      }
      return $output

    } else {
      return [input hidden element $tag_attributes]
    }   

}
Collapse
Posted by Dave Bauer on
Hmmm interesting I wonder what checkbox/radio do with ID since there are multiple widgets with the same name there also.

Looks pretty good but I wonder if it works if you set the widget value implicitly in the *_request block in ad_form. I'll have to see how that would work.

Hi Brian,

id must be unique in the document (http://www.w3.org/TR/html4/struct/global.html#adef-id) so you probably want to do something like:

append output "<input type=\"hidden\" id=\"$element(form_id):$element(name):$value\" name=\"$element(name)\" value=\"$value\">\n"

as it's done for checkbox and radio elements (http://openacs.org/api-doc/proc-view?proc=template::widget::input&source_p=1)

see http://www.w3.org/TR/html4/types.html#type-name for valid ID.