annotate jquery-ui/development-bundle/demos/autocomplete/multiple-remote.html @ 0:b2e4605f20b2

beta version
author dwinter
date Thu, 30 Jun 2011 09:07:49 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
1 <!DOCTYPE html>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
2 <html lang="en">
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
3 <head>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
4 <meta charset="utf-8">
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
5 <title>jQuery UI Autocomplete - Multiple, remote</title>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
6 <link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
7 <script src="../../jquery-1.5.1.js"></script>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
8 <script src="../../ui/jquery.ui.core.js"></script>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
9 <script src="../../ui/jquery.ui.widget.js"></script>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
10 <script src="../../ui/jquery.ui.position.js"></script>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
11 <script src="../../ui/jquery.ui.autocomplete.js"></script>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
12 <link rel="stylesheet" href="../demos.css">
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
13 <style>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
14 .ui-autocomplete-loading { background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat; }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
15 </style>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
16 <script>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
17 $(function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
18 function split( val ) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
19 return val.split( /,\s*/ );
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
20 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
21 function extractLast( term ) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
22 return split( termĀ ).pop();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
23 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
24
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
25 $( "#birds" )
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
26 // don't navigate away from the field on tab when selecting an item
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
27 .bind( "keydown", function( event ) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
28 if ( event.keyCode === $.ui.keyCode.TAB &&
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
29 $( this ).data( "autocomplete" ).menu.active ) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
30 event.preventDefault();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
31 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
32 })
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
33 .autocomplete({
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
34 source: function( request, response ) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
35 $.getJSON( "search.php", {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
36 term: extractLast( request.term )
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
37 }, response );
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
38 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
39 search: function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
40 // custom minLength
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
41 var term = extractLast( this.value );
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
42 if ( term.length < 2 ) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
43 return false;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
44 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
45 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
46 focus: function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
47 // prevent value inserted on focus
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
48 return false;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
49 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
50 select: function( event, ui ) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
51 var terms = split( this.value );
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
52 // remove the current input
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
53 terms.pop();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
54 // add the selected item
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
55 terms.push( ui.item.value );
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
56 // add placeholder to get the comma-and-space at the end
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
57 terms.push( "" );
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
58 this.value = terms.join( ", " );
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
59 return false;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
60 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
61 });
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
62 });
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
63 </script>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
64 </head>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
65 <body>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
66
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
67 <div class="demo">
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
68
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
69 <div class="ui-widget">
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
70 <label for="birds">Birds: </label>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
71 <input id="birds" size="50" />
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
72 </div>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
73
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
74 </div><!-- End demo -->
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
75
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
76
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
77
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
78 <div class="demo-description">
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
79 <p>Usage: Enter at least two characters to get bird name suggestions. Select a value to continue adding more names.</p>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
80 <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>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
81 </div><!-- End demo-description -->
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
82
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
83 </body>
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
84 </html>