Skip to content

Instantly share code, notes, and snippets.

@vilaca
Last active October 25, 2018 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vilaca/f5a17c377683748e9ad6c2ae3efa8c41 to your computer and use it in GitHub Desktop.
Save vilaca/f5a17c377683748e9ad6c2ae3efa8c41 to your computer and use it in GitHub Desktop.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Autocomplete - functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-2.1.0.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<script>
$( function() {
$( "#tags" ).autocomplete({
delay: 20,
minLength: 2,
source: function (request, resp) {
var re = $.ui.autocomplete.escapeRegex(request.term);
var dataSource = "index/" + re.substring(0,2).toLowerCase() + ".json";
var r = $.get(dataSource, request, function (data) {
var matcher = new RegExp( re, "i" );
var a = $.grep( data, function(item,index){
return matcher.test(item);
});
resp(a);
});
}
});
} );
</script>
</head>
<body>
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags">
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment