Created
January 28, 2011 13:38
-
-
Save alfredwesterveld/800259 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>jQuery UI Autocomplete - Default functionality</title> | |
| <link rel="stylesheet" href="jquery-ui-1.8.9.custom/css/ui-lightness/jquery-ui-1.8.9.custom.css"> | |
| <script src="jquery-ui-1.8.9.custom/js/jquery-1.4.4.min.js"></script> | |
| <script src="jquery-ui-1.8.9.custom/js/jquery-ui-1.8.9.custom.min.js"></script> | |
| <script> | |
| $(function() { | |
| var LIMIT = 10; | |
| $.getJSON("json.json", function(data) { | |
| var autocomplete = $( "#tags" ).autocomplete({ | |
| source: function( request, response ) { | |
| var i=0; | |
| var result = []; | |
| var term = request.term.toLowerCase(); | |
| $.each(data, function(index, value) { | |
| // value.value.search(/request.term/i); | |
| var idx = value.value.toLowerCase().indexOf(term); | |
| if (idx >= 0) { | |
| result.push(value.value); | |
| i++; | |
| } | |
| if (i === LIMIT) { | |
| return false; | |
| } | |
| }); | |
| response(result); | |
| } | |
| }); | |
| $( "#tags").blur(function() { | |
| var inputValue = $( "#tags" ).val(); | |
| var clear = true; | |
| $.each(data, function(index, value) { | |
| if (value.value == inputValue) { | |
| clear = false; | |
| return false; | |
| } | |
| }); | |
| if (clear) { | |
| $( "#tags" ).val(""); | |
| } | |
| }); | |
| }); | |
| }); | |
| </script> | |
| </head> | |
| <body> | |
| <div class="demo"> | |
| <div class="ui-widget"> | |
| <label for="tags">Tags: </label> | |
| <input id="tags" /> | |
| </div> | |
| </div><!-- End demo --> | |
| <div class="demo-description"> | |
| <p>The Autocomplete widgets provides suggestions while you type into the field. Here the suggestions are tags for programming languages, give "ja" (for Java or JavaScript) a try.</p> | |
| <p>The datasource is a simple JavaScript array, provided to the widget using the source-option.</p> | |
| </div><!-- End demo-description --> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [{"id":1,"value":"ActionScript"},{"id":2,"value":"AppleScript"},{"id":3,"value":"Asp"},{"id":4,"value":"BASIC"},{"id":5,"value":"C"},{"id":6,"value":"C++"},{"id":7,"value":"Clojure"},{"id":8,"value":"COBOL"},{"id":9,"value":"ColdFusion"},{"id":10,"value":"Erlang"},{"id":11,"value":"Fortran"},{"id":12,"value":"Groovy"},{"id":13,"value":"Haskell"},{"id":14,"value":"Java"},{"id":15,"value":"JavaScript"},{"id":16,"value":"Lisp"},{"id":17,"value":"Perl"},{"id":18,"value":"PHP"},{"id":19,"value":"Python"},{"id":20,"value":"Ruby"},{"id":21,"value":"Scala"},{"id":21,"value":"Scheme"}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment