Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lift Ajax multi select box

I am new to scala and lift and I want to make a form with some ajax. Therefore main form is from normal stateful snippet and middle content is enclosed with some ajax form(there content in another snippet but not Stateful because I cant use ValueCell in Stateful).

In there I want to add dynamically any no. of multi-select boxes as user want by pressing "ADD" button.

I did it for normal drop-down select by selecting SHtml.ajaxSelect() and save in ValueCell and also save in a session context.

Here I can use ValueCell to store data because ajaxSelect support for ajax. But in multi-select there are not "ajaxMultiSelect"?? So I need to retrieve the data from those dynamically added multi-select boxes to my form variables when pressing submit button in the overall form.

http://seventhings.liftweb.net/wiring - this example is my guide to do my task. Here they use dynamically add text fields. But I want to add multiselect and save data when hitting submit button.

Please help me someone. If u want further clarification I can give.

Thank you ALL...

like image 256
Arosh Avatar asked Jan 26 '12 19:01

Arosh


1 Answers

If all you want is multi-selects whose values can be sent to the server when user pushes a "save" button, then a bunch of SHtml.multiselect objects on an AJAX form should be sufficient.

On the other hand, if you need an AJAX call every time the user changes the value of a multi-select then you probably have to use the same SHtml.multiselect but add an onchange event handler that calls a JavaScript function containing an ajaxCall.

Here's a bit that creates a JavaScript function doCallback() and adds it to the page at #placeholder. This calls commandCallback(commandString) on the server.

val log = SHtml.ajaxCall(JsRaw("commandString"), commandCallback _)._2.cmd
val f = JsCmds.Function("doCallback", List[String](), log)
("#placeholder" #> JsCmds.Script(f)).apply(ns)
like image 136
Donald.McLean Avatar answered Nov 19 '22 22:11

Donald.McLean