Forum OpenACS Q&A: ad_form and multiple

Collapse
Posted by Cathy Sarisky on
Ad_form has me stumped again. I have a multiple selection widget defined in ad_form:
{hallmarks:text(multiselect) {label "Hallmarks"}
    {values "$hallmarks"}
    {options {{Scholarship 1} {Leadership 2} {Fellowship 3} {Service 4}} }
    {html {size 4}}
}
That gives me a form for editing with the four choices able to be selected. (I also needed to set it as {hallmarks:multiple ""} in ad_page_contract.)

Hitting the submit button gets the multiply selected values of hallmarks through ad_page_contract, but then something seems to go amiss in ad_form. A ns_log entry down in the -new_data area (or -edit_data) shows that only the first selection appears in $hallmarks. Any additional selections are somehow lost.

I also tried replacing the {values "$hallmarks"} in the code snippet above with {values "1 2 3"}, with the same result: only the first value seems to make it into -new_data or -edit_data.

I grepped through the existing packages looking for some example code using ad_form with multiple selection, but I haven't found any.

Sorry for going on and on. I'm hoping that documenting my confusion will be useful to the folks working on ad_form documentation. If anyone has a working (even if ugly) example of using ad_form with multiselect, it would really help me to see one. Thanks in advance. :)

--Cathy

Collapse
2: Re: ad_form and multiple (response to 1)
Posted by Jon Griffin on
Cathy,

There is some code on another project I can get at tomorrow, if no one else does before then. It uses multiple check boxes so I believe it should work.

If I don't see an answer in the morning I will dig this code up for you.

Collapse
3: Re: ad_form and multiple (response to 1)
Posted by Don Baccus on
You need to tell it that it is multiple ... try

text(multiselect),multiple

Sorry about that but the form builder treats multiples as being different than other stuff and as ad_form is just wrapping the form builder with a (hopefully) more user-friendly API ...

ad_form is still a bit of an experiment...and the form builder incomplete.  Ideally ad_form (and the form builder) whould know that a "multiselect" datatype might return (will often return) mulitiple values.  But that's not the case, yet.  The form builder expects the programmer to tell it if this is true (silly since "multiselect" implies it) and ad_form blindly exports that API to you.

Obviously the whole form builder concept of a datatype needs to be extended so that our core code does what one expects, so that the form builder and ad_form follow the law of "least astonishment" when they take action.

I'm not quite sure when we'll get there.  Other core issues have seemed more relevant to me (non-scalability of permissions for instance.)  Others have picked up the slack in other areas, Peter in the APM (great work), Joel in documentation (ditto), Jeff in patch and release work (and Janine, too) and dozens of others in various subrealms of the project.

But we're getting to the point where "rapid development" is going to be a key concept, and cleaning up the form builder (and by inference ad_form) is going to be a top, top priority ...

Collapse
4: Re: ad_form and multiple (response to 1)
Posted by Cathy Sarisky on
That's got it, thank you Don!  Jon, this might be a good spot for more documentation on ad_form - would you like me to write up a snippet with a (finally working) example to add to what you have?

While I'm here, let me comment that 4.6.2 seems MUCH more polished than 4.6.0, which is the last release I played with at all.  The effort all around really shows. :)

ad_form is driving me a little bit crazy (more examples will help), but at the same time, I've been impressed several times this weekend about what it did for me automatically.  It seems like once one has the hang of it, data entry, validation, and editing requires VERY little coding compared to the PAINFULLY slow way I did it for my 3.2.5 site.

Collapse
5: Re: ad_form and multiple (response to 1)
Posted by Don Baccus on
Yes, this would be a good thing to add to Jon's doc and actually I should doc it directly in the proc header.  Eventually I want to remove the need to add the "multiple" attribute but it will require some changes in the form builder proper to do this.
Collapse
6: Re: ad_form and multiple (response to 1)
Posted by Gabriel Ricard on
Perhaps something along the lines of an "ad_form Cookbook" would be most useful? I imagine that there is numerous reproduction and duplication of various types of forms out there. It'd be nice to have a one-stop-shop one could visit to  find "recipes" for forms in OpenACS.
Collapse
7: Re: ad_form and multiple (response to 1)
Posted by Frank Bergmann on
Hi Guys,

I just want to let you know that I've got stuck by the same - how to call this? - feature, losing about two hours, because I first tried to understand the documentation. Also, the user-add.tcl page uses a "-query" feature in ad_page_contact that is not documented in 5.0.rc1.

Bests,
Frank

Collapse
8: Re: ad_form and multiple (response to 7)
Posted by Jade Rubick on
Please file a bug on the lack of documentation. This undocumented stuff needs to stop.
Collapse
9: Re: ad_form and multiple (response to 1)
Posted by Randy O'Meara on
ad_page_contract's -query param is documented...somewhere. Stating it explicitly is optional. It's been there forever. I just don't recall where I found the doc for it.

Randy

Collapse
10: Re: ad_form and multiple (response to 1)
Posted by rod santiago on
i got a same promlem... Pls. do help...

how could i retrieve all the selected value from the multiselect?

it does only return only one...

Pls do help...

THANKs