Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to trigger the auto search option of multiple-remote jquery autocomplete UI
    text
    copied!<p>I am using this auto complete library: <a href="http://jqueryui.com/demos/autocomplete/#multiple-remote" rel="nofollow">http://jqueryui.com/demos/autocomplete/#multiple-remote</a></p> <p>I was wondering if anyone knows how trigger the auto search without typing anything in the text box. i.e. if we want to display the list on a button click event. the "search" method seems to be doing that. But I cant get it working.</p> <p>Please note that the data of the auto suggest comes from a web service. If user types something in the text box the suggestion changes accordingly. i.e. the typed data goes to the service and brings back the suggestion. The input is of "Name, Location" form. As a result for different parts of the input different types of suggestions are displayed.</p> <p>Codes:</p> <p>UI:</p> <pre><code>&lt;div class="ui-widget"&gt; &lt;label for="birds"&gt;Birds: &lt;/label&gt; &lt;input id="birds" size="50" /&gt; &lt;/div&gt; </code></pre> <p>Script:</p> <pre><code>&lt;script&gt; $(function() { function split( val ) { return val.split( /,\s*/ ); } function extractLast( term ) { return split( term ).pop(); } $( "#birds" ) .bind( "keydown", function( event ) { if ( event.keyCode === $.ui.keyCode.TAB &amp;&amp; $( this ).data( "autocomplete" ).menu.active ) { event.preventDefault(); } }) .autocomplete({ source: function( request, response ) { $.getJSON( "search.php", { term: extractLast( request.term ) }, response ); }, search: function() { var term = extractLast( this.value ); if ( term.length &lt; 2 ) { return false; } }, focus: function() { return false; }, select: function( event, ui ) { var terms = split( this.value ); terms.pop(); terms.push( ui.item.value ); terms.push( "" ); this.value = terms.join( ", " ); return false; } }); }); &lt;/script&gt; </code></pre> <p>If I type anything it sends a request to search.php. I tried changing the logic "term.length &lt; 2" to "term.length &lt;= 0". This works but i have to press the space bar. Then an empty space is placed in the text box and is sends the request to the server. But I don't want to type anything in there. Hope that helps.</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