5 <title>jQuery UI Autocomplete - Multiple, remote</title>
6 <link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
7 <script src="../../jquery-1.9.1.js"></script>
8 <script src="../../ui/jquery.ui.core.js"></script>
9 <script src="../../ui/jquery.ui.widget.js"></script>
10 <script src="../../ui/jquery.ui.position.js"></script>
11 <script src="../../ui/jquery.ui.menu.js"></script>
12 <script src="../../ui/jquery.ui.autocomplete.js"></script>
13 <link rel="stylesheet" href="../demos.css">
15 .ui-autocomplete-loading {
16 background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat;
21 function split( val ) {
22 return val.split( /,\s*/ );
24 function extractLast( term ) {
25 return split( termĀ ).pop();
29 // don't navigate away from the field on tab when selecting an item
30 .bind( "keydown", function( event ) {
31 if ( event.keyCode === $.ui.keyCode.TAB &&
32 $( this ).data( "ui-autocomplete" ).menu.active ) {
33 event.preventDefault();
37 source: function( request, response ) {
38 $.getJSON( "search.php", {
39 term: extractLast( request.term )
44 var term = extractLast( this.value );
45 if ( term.length < 2 ) {
50 // prevent value inserted on focus
53 select: function( event, ui ) {
54 var terms = split( this.value );
55 // remove the current input
57 // add the selected item
58 terms.push( ui.item.value );
59 // add placeholder to get the comma-and-space at the end
61 this.value = terms.join( ", " );
70 <div class="ui-widget">
71 <label for="birds">Birds: </label>
72 <input id="birds" size="50">
75 <div class="demo-description">
76 <p>Usage: Enter at least two characters to get bird name suggestions. Select a value to continue adding more names.</p>
77 <p>This is an example showing how to use the source-option along with some events to enable autocompleting multiple values into a single field.</p>