Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you want to trigger the search when a button is clicked, then you have to call the search method. If you want to show all options, call search with the value set to empty string and set the autocomplete widget to accept minLength: 0. </p> <p>So in code:</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;input type="button" id="search-trigger" value="Trigger" /&gt; &lt;/div&gt; </code></pre> <p>Script</p> <pre><code>&lt;script type="text/javascript"&gt; $(function() { function split( val ) { return val.split( /,\s*/ ); } function extractLast( term ) { return split( term ).pop(); } // Button listener that triggs the search event $("#search-trigger").click(function(){ var searchTerm = $( "#birds" ).val(); $( "#birds" ).autocomplete( "search" , searchTerm); }); $( "#birds" ) .bind( "keydown", function( event ) { if ( event.keyCode === $.ui.keyCode.TAB &amp;&amp; $( this ).data( "autocomplete" ).menu.active ) { event.preventDefault(); } }) .autocomplete({ source: ["lorem", "ipsum", "dolor"], /* Commented this out to use dummy data above function( request, response ) { $.getJSON( "search.php", { term: extractLast( request.term ) }, response ); },*/ search: function() { var term = extractLast( this.value ); /* What is this check for? 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; }, //Added for "show all" support minLength: 0 }); }); &lt;/script&gt; </code></pre> <p>Is this the behavior you are looking for?</p> <p>Ref: <a href="http://jqueryui.com/demos/autocomplete/#method-search" rel="nofollow">http://jqueryui.com/demos/autocomplete/#method-search</a></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