autocompleteObj fails to bind selected object on submit
As default, the associated hidden field takes as value a generated "nonce" (term from the source code).
Once a value provided by the auto-completion is selected, the hidden field value attribute is set to the selected name.
This is done by the anonymous function given as parameter to the function "result" of the autocomplete js object.
On form submit, because the hidden field value is not one of the "nonce", the given onSubmit callback is not called.
net.liftweb.widgets.autocomplete.AutoComplete
I think there should have a specific "autocomplete_*" definition for autocompleteObj with a closure that recover the corresponding "nonce" that match the selected "name".
And then set the hidden field value attribute with this recovered "nonce".
Once a value provided by the auto-completion is selected, the hidden field value attribute is set to the selected name.
This is done by the anonymous function given as parameter to the function "result" of the autocomplete js object.
On form submit, because the hidden field value is not one of the "nonce", the given onSubmit callback is not called.
net.liftweb.widgets.autocomplete.AutoComplete
private def autocomplete_*(options: Seq[(String, String)], default: Box[String],
defaultNonce: Box[String], onSubmit: AFuncHolder, jsonOptions: List[(String,String)]): Elem = {
val id = Helpers.nextFuncName
fmapFunc(onSubmit){hidden =>
val data = JsArray(options.map {
case (nonce, name) => JsObj("name" -> name, "nonce" -> nonce)
} :_*)
/* merge the options that the user wants */
val jqOptions = ("minChars","0") ::
("matchContains","true") ::
("formatItem","function(row, i, max) { return row.name; }") ::
Nil ::: jsonOptions
val json = jqOptions.map(t => t._1 + ":" + t._2).mkString("{", ",", "}")
val autocompleteOptions = JsRaw(json)
val onLoad = JsRaw("""
jQuery(document).ready(function(){
var data = """+data.toJsCmd+""";
jQuery("#"""+id+"""").autocomplete(data, """+autocompleteOptions.toJsCmd+""").result(function(event, dt, formatted) {
jQuery("#"""+hidden+"""").val(formatted);
});
});""")
...
}
I think there should have a specific "autocomplete_*" definition for autocompleteObj with a closure that recover the corresponding "nonce" that match the selected "name".
And then set the hidden field value attribute with this recovered "nonce".
Leave a comment