| 1 | <!doctype html> |
| 2 | <html lang="en"> |
| 3 | <head> |
| 4 | <meta charset="utf-8"> |
| 5 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 6 | <title>jQuery UI Autocomplete - Remote datasource</title> |
| 7 | <link rel="stylesheet" href="../../themes/base/all.css"> |
| 8 | <link rel="stylesheet" href="../demos.css"> |
| 9 | <style> |
| 10 | .ui-autocomplete-loading { |
| 11 | background: white url("images/ui-anim_basic_16x16.gif") right center no-repeat; |
| 12 | } |
| 13 | </style> |
| 14 | <script src="../../external/requirejs/require.js"></script> |
| 15 | <script src="../bootstrap.js"> |
| 16 | function log( message ) { |
| 17 | $( "<div>" ).text( message ).prependTo( "#log" ); |
| 18 | $( "#log" ).scrollTop( 0 ); |
| 19 | } |
| 20 | |
| 21 | $( "#birds" ).autocomplete({ |
| 22 | source: "search.json", |
| 23 | minLength: 2, |
| 24 | select: function( event, ui ) { |
| 25 | log( "Selected: " + ui.item.value + " aka " + ui.item.id ); |
| 26 | } |
| 27 | }); |
| 28 | </script> |
| 29 | <script src="../search.js"></script> |
| 30 | </head> |
| 31 | <body> |
| 32 | |
| 33 | <div class="ui-widget"> |
| 34 | <label for="birds">Birds: </label> |
| 35 | <input id="birds"> |
| 36 | </div> |
| 37 | |
| 38 | <div class="ui-widget" style="margin-top:2em; font-family:Arial"> |
| 39 | Result: |
| 40 | <div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div> |
| 41 | </div> |
| 42 | |
| 43 | <div class="demo-description"> |
| 44 | <p>The Autocomplete widgets provides suggestions while you type into the field. Here the suggestions are bird names, displayed when at least two characters are entered into the field.</p> |
| 45 | <p>The datasource is a server-side script which returns JSON data, specified via a simple URL for the source-option. In addition, the minLength-option is set to 2 to avoid queries that would return too many results and the select-event is used to display some feedback.</p> |
| 46 | </div> |
| 47 | </body> |
| 48 | </html> |