Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For the peeps who might be dealing with the same situation, here is the <b>solution</b> i came up with, a brief explanation first:<br></p> <ul> <li>First, i <b> split</b> the search term (query) on white space</li> <li>I then dynamically build a regex definition by concatenating the <b> splitted words</b> with some more regex attributes. <b>For example</b>: say user searches for <b>"Car Bike"</b> --> after splitting i dynamically build the following string:<br> [<i>str = <b>"Car"</b>+(any character(s))+<b>"Bike"</b>+(any character(s))</i>] , which is then fed to javascript <b>RegExp</b>.</li> </ul> <p>To make it more clear, here is my <b>Code:(hopefully it might help you)</b></p> <pre><code>$( "#field" ).autocomplete({ source:function(request, response) { var query_array = request.term.toUpperCase().split(/\s+/g);//split on white space if(query_array.length &gt;1)// if two ore more words, separated by whitespace { if(!/^\s*$/.test(query_array[query_array.length-1]))//if last word is not only whitespace { var new_query = ''; for (var i=0; i&lt;query_array.length; ++i ) { new_query+='(\\b' +query_array[i]+'\\b)';//word boundaries if(i&lt;query_array.length-1) { new_query+="([\\s\\S\\.]*)";// match ALL characters including newline , * is for many } } var matcher = new RegExp('^'+new_query, "g");//must Start with query term, apply regex global var a = $.grep( autocomplete_data_array, function(item,index){ return matcher.test(item.value); }); if(a.length&gt;0) { response(a); } } } </code></pre>
    singulars
    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.
 

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