Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I know this is a bit of an older question, but here's my shot (since there still doesn't appear to be an ajax multiSelect in the latest snapshots), and I could see it coming in handy</p> <p>You can base it off of the regular ajaxSelect. The main changes are:</p> <ol> <li>You have to extract all the values and submit them (the form submission is just regular urlEncoded postParams), but this is the most unclear if you are just glancing at how to do this.</li> <li>You have to change the default value to a Seq[String] (this also requres changing the test to see if selected should be set)</li> <li><p>You have to decide whether you want the callback on change or on blur. In my example, I'll make it onblur, but you could make it configurable.</p> <pre><code> private def ajaxMultiSelect_*(opts: Seq[(String, String)], deflt: Seq[String], jsFunc: Box[Call], func: AFuncHolder, attrs: ElemAttr*): Elem = { val optionSelect = """function(funcName, element) { | var postData = "" | var i = 0; | var k = 0; | for (k = 0; k &lt; element.length; k++) { | if (element[k].selected) { | if (i == 0) | postData = funcName + '=' + encodeURIComponent(element[k].value); | else { | postData = postData + '&amp;' + funcName + '=' + encodeURIComponent(element[k].value); | } | i++; | } | } | return postData; |}""".stripMargin val raw = (funcName: String, value: String) =&gt; JsRaw(optionSelect + "('" + funcName + "'," + value + ")") val key = formFuncName val vals = opts.map(_._1) val testFunc = LFuncHolder(in =&gt; in.filter(v =&gt; vals.contains(v)) match {case Nil =&gt; false case xs =&gt; func(xs)}, func.owner) fmapFunc((testFunc)) { funcName =&gt; (attrs.foldLeft(&lt;select multiple="multiple"&gt;{opts.flatMap {case (value, text) =&gt; (&lt;option value={value}&gt;{text}&lt;/option&gt;) % selected(default.contains(value)))}}&lt;/select&gt;)(_ % _)) % ("onblur" -&gt; (jsFunc match { case Full(f) =&gt; JsCrVar(key, JsRaw("this")) &amp; deferCall(raw(funcName, key), f) case _ =&gt; makeAjaxCall(raw(funcName, "this")) })) } } </code></pre></li> </ol> <p>This should be working, but I didn't test it. If I have time, I'll test it and see if I can get it (and its overloads) added to the master branch.</p> <p>Good Luck!</p> <p>-Austen</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload