Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>With the help of Dave Whittaker, here is the solution I came with. </p> <p>I had to change some behaviors to get: </p> <ul> <li>the desired text (from autocomplete or not) in an ajaxText element</li> <li>the possibility to have multiple autocomplete forms on same page</li> <li>submit answer on ajaxText before blurring when something is selected in autocomplete suggestions. </li> </ul> <p><strong>Scala part</strong></p> <pre><code>private def getSugggestions(current: String, limit: Int):List[String] = { /* returns list of suggestions */ } private def autoCompleteJs = AnonFunc("term, res",JsRaw( (S.fmapFunc(S.contextFuncBuilder(SFuncHolder({ terms: String =&gt; val _candidates = if(terms != null &amp;&amp; terms.trim() != "") getSugggestions(terms, 5) else Nil JsonResponse(JArray(_candidates map { c =&gt; JString(c)/*.toJson*/ })) }))) ({ name =&gt; "liftAjax.lift_ajaxHandler('" + name })) + "=' + encodeURIComponent(term), " + "function(data){ res(data); }" + ", null, 'json');")) def xml = { val id = "myId" //possibility to have multiple autocomplete fields on same page Script(OnLoad(JsRaw("jQuery('#"+id+"').createAutocompleteField("+autoCompleteJs.toJsCmd+")"))) ++ SHtml.ajaxText(cell.get, s=&gt;{ cell.set(s); SearchMenu.recomputeResults; Noop}, "id" -&gt; id) } </code></pre> <p><strong>Script to insert into page header:</strong></p> <pre><code>(function($) { $.fn.createAutocompleteField = function(search) { return this.autocomplete({ autoFocus: true, source: function(req, res) { search(req.term, res); }, select: function(event, ui) { $(this).val(ui.item.value); $(this).blur(); }, focus: function(event, ui) { event.preventDefault(); } }); } })(jQuery); </code></pre> <p><em>Note: I accepted Dave's answer, mine is just to provide a complete answer for my purpose</em></p>
 

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