My previous "multiselect" usage was as follows:
SHtml.multiSelect(nameOpt, existingNames, existingNames = _, ("size" -> math.min(20, nameOpt.size).toString), ("style" -> "min-width:400px"))
The example data was: Brad, Angelina, Morgan, Fred, Tom, Huan
Now....I am trying to replace that multiselect with the new method (myNewMultiSelect_*) that I newly created with the goal of creating an editable multiselect, but for now I would like to know how to make a method call with appropriate values just like in the multiselect
Well, I am not clear about 2 parameters: 1 - jsFunc: Box[Call]
2 - func (I think this is the same as my "existingNames = _"). Not sure though. Because AFuncHolder is a sealed trait that extends List[String => Any and that is what we have in the multiselect
All I want to accomplish right now is to display the same multiselect box as before, with the following new code.
What value do you think I can pass into the jsFunc parameter - the highlighted parameter
def myNewMultiSelect_*(opts: Seq[(String, String)], deflt: Seq[String], jsFunc:Box[Call],
func: S.AFuncHolder, attrs: ElemAttr*)(onSubmit: (T) => Any)(implicit f:PairStringPromoter[T]):Elem = {
println("Entered ajaxMultiSelectEdit")
val optionSelect =
"""function(funcName, element) {
| var postData = ""
| var i = 0;
| var k = 0;
| for (k = 0; k < element.length; k++) {
| if (element[k].selected) {
| if (i == 0)
| postData = funcName + '=' + encodeURIComponent(element[k].value);
| else {
| postData = postData + '&' + funcName + '=' + encodeURIComponent(element[k].value);
| }
| i++;
| }
| }
| return postData;
|}""".stripMargin
println("optionSelect is: " + optionSelect)
//val raw = (funcName: String, value: String) ⇒ JsRaw("'" + funcName + "=' + encodeURIComponent(" + value + ".value)")
val raw = (funcName: String, value: String) => JsRaw(optionSelect + "('" +funcName + "'," + value +")")
val key = S.formFuncName
//val key = funcName
val vals = opts.map(_._1)
val testFunc = S.LFuncHolder(in => in.filter(v => vals.contains(v)) match {case Nil =>false case xs=> func(xs)}, func.owner)
S.fmapFunc(S.contextFuncBuilder(testFunc)) {
//S.fmapFunc((testFunc)) {
funcName =>
(attrs.foldLeft(<select multiple="multiple">
{opts.flatMap {case (value, text) => (<option value={value}>
{text}
</option>) % selected(deflt.contains(value))
}}</select>)(_ % _)) %
("onchange" -> (jsFunc match {
//(jsFunc match {
case Full(f) => JsCrVar(key, JsRaw("this")) &net.liftweb.http.js.JsCmds.jsExpToJsCmd(SHtml.makeAjaxCall(raw(funcName,"this")))
case _ => net.liftweb.http.js.JsCmds.jsExpToJsCmd(SHtml.makeAjaxCall(raw(funcName,"this"))) //def makeAjaxCall(in: JsExp): JsExp
}))
}
}