Forum OpenACS Development: multiple hidden widget?

Collapse
Posted by Jeff Lu on
Is there such a thing as a multiple hidden widget? Something that behaves like multiple checkboxes?
Collapse
Posted by Tom Jackson on

There would be no point to a hidden widget of this type. A user cannot choose from hidden choices. You must mean to so something else, can you describe what that is? You can name hidden inputs anything you like, so just change type="checkbox" to type="hidden", but the values need to be filled in of course.

Collapse
Posted by Jeff Lu on
The behavior that I meant is that the hidden widget can have multiple values.

<input type="hidden" name="hidden1" value="1">
<input type="hidden" name="hidden1" value="2">
<input type="hidden" name="hidden1" value="3">

I tried this
template::element create formname hidden1 -widget hidden -value 1
template::element create formname hidden1 -widget hidden -value 2

But it will result in an error since the element hidden1 is already defined.

Collapse
Posted by Dave Bauer on
Jeff

Usually you can pass the -values switch with a list of values for a multiple value widget, did you try that with the hidden widget?

Collapse
Posted by Jeff Lu on
The "-values" doesnt seem to work. Ive tried it for both ad_form and template::form. It seems when I use -values the value for the widget is "" (empty) so it wont go to the "-after_submit" portion of the ad_form since the hidden widget was not valid. The errors werent displayed on screen since the error was on the hidden widget.
Collapse
Posted by Roberto Mello on
Try passing something like {1 2 3} as the value of that widget. That way it'll be a Tcl list, which you can then process easily.

-Roberto

Collapse
Posted by Jeff Lu on

Thanks Robert. Thats the workaround that I came up with too. Im really sorry for the ambiguity of my first post. Let me explain what I am really doing. I made 2 pages. A delete page and a delete confirmation page. For the delete page this is how I did it:


<form action="message-delete">
<multiple name="messages">
<input type="checkbox" name="message_id" value="@messages.message_id@"> </multiple> So the for the tcl of the confirmation page I did this:
ad_page_contract { } { 
        {message_id:multiple}
}
#here message_id is a multiple to get the multiple values #from the delete page
ad_form -name delete-message -form {
{submit.x:text(submit) {label "delete"}}
{cancel.x:text(submit) {label "cancel"}}
{message_id:integer(hidden),multiple {value $message_id}}

#for the message_id part I tried both values and value when I tried using values the form was resubmitted but was not rendered properly because of validation error on the values part. When I tried using value the values of the message_ids were preserved but it returns a list with one element like this : {val1 val2 val3} as opposed to {val1} {val2} {val3} when using multiple

} -after_submit {
#submit code here
}

now my problem is the ad_form part. I tried Dave's suggestion (thanks Dave!) but it seems that ad_form sees that the -values part for the hidden widget is invalid. So when It resubmits to itself the message_id which should be a multiple is now a list.