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

Posted by Brian Fenton on
Thanks Emmanuelle, that ID looks good.

Dave, I'm not using ad_form, just with template::form, so it may well break there.

Thanks for the feedback!


Posted by Brian Fenton on
Just coming back to this. We ran into 2 problems with it - one, using $value in the id led to problems if the value contained spaces or other non-valid characters; 
two, for some reason I never figured out, the new widget messed up ad_form code like the following where you're looping and extending the form with multiple hidden elements:
  foreach {operand_pretty operand_id} $operand_el {
    if {$operand_id eq ""} {continue}
    set operand_id [lindex [split $operand_id ,] 1]
    lappend operand_element_ids $operand_id
    ad_form -extend -name calc_form -form {
        {$operand_id:text(hidden) {html {id $operand_id}} {value 1}}

So here's a new version of the proc which solves both of those problems. It now expects an attribute called "-multivalues" instead of "-values."

ad_proc -public template::widget::hidden {

    @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(multivalues)] } {
      set multivalues $element(multivalues)
      set output {}
      set count 0
      foreach itemvalue $multivalues {
        set itemvalue [ad_quotehtml $itemvalue]
        append output "<input type=\"hidden\" id=\"$element(form_id):$element(name):$count\" name=\"$element(name)\" value=\"$itemvalue\">\n"
        incr count
      return $output

    } else {
      return [input hidden element $tag_attributes]