[24245] | 1 | <!doctype html>
|
---|
| 2 | <html>
|
---|
| 3 | <head>
|
---|
| 4 | <title>jQuery UI Autocomplete Remote datasource demo</title>
|
---|
| 5 | <link type="text/css" href="../../themes/base/ui.all.css" rel="stylesheet" />
|
---|
| 6 | <script type="text/javascript" src="../../jquery-1.4.1.js"></script>
|
---|
| 7 | <script type="text/javascript" src="../../ui/jquery.ui.core.js"></script>
|
---|
| 8 | <script type="text/javascript" src="../../ui/jquery.ui.widget.js"></script>
|
---|
| 9 | <script type="text/javascript" src="../../ui/jquery.ui.position.js"></script>
|
---|
| 10 | <script type="text/javascript" src="../../ui/jquery.ui.autocomplete.js"></script>
|
---|
| 11 | <link type="text/css" href="../demos.css" rel="stylesheet" />
|
---|
| 12 | <script type="text/javascript">
|
---|
| 13 | $(function() {
|
---|
| 14 | function log(message) {
|
---|
| 15 | $("<div/>").text(message).prependTo("#log");
|
---|
| 16 | $("#log").attr("scrollTop", 0);
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | $("#birds").autocomplete({
|
---|
| 20 | // TODO doesn't work when loaded from /demos/#autocomplete|remote
|
---|
| 21 | source: "search.php",
|
---|
| 22 | minLength: 2,
|
---|
| 23 | select: function(event, ui) {
|
---|
| 24 | log(ui.item ? ("Selected: " + ui.item.value + " aka " + ui.item.id) : "Nothing selected, input was " + this.value);
|
---|
| 25 | }
|
---|
| 26 | });
|
---|
| 27 | });
|
---|
| 28 | </script>
|
---|
| 29 | </head>
|
---|
| 30 | <body>
|
---|
| 31 |
|
---|
| 32 | <div class="demo">
|
---|
| 33 |
|
---|
| 34 | <div class="ui-widget">
|
---|
| 35 | <label for="birds">Birds: </label>
|
---|
| 36 | <input id="birds" />
|
---|
| 37 | </div>
|
---|
| 38 |
|
---|
| 39 | <div class="ui-widget" style="margin-top:2em; font-family:Arial">
|
---|
| 40 | Result:
|
---|
| 41 | <div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div>
|
---|
| 42 | </div>
|
---|
| 43 |
|
---|
| 44 | </div><!-- End demo -->
|
---|
| 45 |
|
---|
| 46 | <div class="demo-description">
|
---|
| 47 | <p>
|
---|
| 48 | 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.
|
---|
| 49 | </p>
|
---|
| 50 | <p>
|
---|
| 51 | 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.
|
---|
| 52 | </p>
|
---|
| 53 | </div><!-- End demo-description -->
|
---|
| 54 |
|
---|
| 55 | </body>
|
---|
| 56 | </html>
|
---|