2012-09-10 15:33:46 +00:00
|
|
|
<!doctype html>
|
2010-04-16 09:05:35 +00:00
|
|
|
<html lang="en">
|
|
|
|
<head>
|
2010-09-10 02:24:52 +00:00
|
|
|
<meta charset="utf-8">
|
2015-09-30 13:11:22 +00:00
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
2010-09-10 02:33:09 +00:00
|
|
|
<title>jQuery UI Autocomplete - Multiple, remote</title>
|
2013-12-02 18:36:12 +00:00
|
|
|
<link rel="stylesheet" href="../../themes/base/all.css">
|
2010-09-10 02:24:52 +00:00
|
|
|
<link rel="stylesheet" href="../demos.css">
|
|
|
|
<style>
|
2011-05-27 12:32:48 +00:00
|
|
|
.ui-autocomplete-loading {
|
2014-01-24 21:18:30 +00:00
|
|
|
background: white url("images/ui-anim_basic_16x16.gif") right center no-repeat;
|
2011-05-27 12:32:48 +00:00
|
|
|
}
|
2010-07-19 13:41:21 +00:00
|
|
|
</style>
|
2015-06-30 19:22:59 +00:00
|
|
|
<script src="../../external/requirejs/require.js"></script>
|
|
|
|
<script src="../bootstrap.js">
|
2010-09-10 02:24:52 +00:00
|
|
|
function split( val ) {
|
|
|
|
return val.split( /,\s*/ );
|
2010-04-16 09:05:35 +00:00
|
|
|
}
|
2010-09-10 02:24:52 +00:00
|
|
|
function extractLast( term ) {
|
2016-06-08 17:03:42 +00:00
|
|
|
return split( term ).pop();
|
2010-04-16 09:05:35 +00:00
|
|
|
}
|
2010-09-10 02:24:52 +00:00
|
|
|
|
2010-11-19 21:17:52 +00:00
|
|
|
$( "#birds" )
|
|
|
|
// don't navigate away from the field on tab when selecting an item
|
2015-05-14 01:54:08 +00:00
|
|
|
.on( "keydown", function( event ) {
|
2010-11-19 21:17:52 +00:00
|
|
|
if ( event.keyCode === $.ui.keyCode.TAB &&
|
2013-01-30 14:30:35 +00:00
|
|
|
$( this ).autocomplete( "instance" ).menu.active ) {
|
2010-11-19 21:17:52 +00:00
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.autocomplete({
|
|
|
|
source: function( request, response ) {
|
|
|
|
$.getJSON( "search.php", {
|
|
|
|
term: extractLast( request.term )
|
|
|
|
}, response );
|
|
|
|
},
|
|
|
|
search: function() {
|
|
|
|
// custom minLength
|
|
|
|
var term = extractLast( this.value );
|
|
|
|
if ( term.length < 2 ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
focus: function() {
|
2012-05-16 13:43:49 +00:00
|
|
|
// prevent value inserted on focus
|
2010-11-19 21:17:52 +00:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
select: function( event, ui ) {
|
|
|
|
var terms = split( this.value );
|
|
|
|
// remove the current input
|
|
|
|
terms.pop();
|
|
|
|
// add the selected item
|
|
|
|
terms.push( ui.item.value );
|
|
|
|
// add placeholder to get the comma-and-space at the end
|
|
|
|
terms.push( "" );
|
|
|
|
this.value = terms.join( ", " );
|
2010-04-16 09:05:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-11-19 21:17:52 +00:00
|
|
|
});
|
2010-04-16 09:05:35 +00:00
|
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<div class="ui-widget">
|
|
|
|
<label for="birds">Birds: </label>
|
2011-05-27 12:32:48 +00:00
|
|
|
<input id="birds" size="50">
|
2010-04-16 09:05:35 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="demo-description">
|
2010-09-10 02:24:52 +00:00
|
|
|
<p>Usage: Enter at least two characters to get bird name suggestions. Select a value to continue adding more names.</p>
|
|
|
|
<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>
|
2012-09-10 15:33:46 +00:00
|
|
|
</div>
|
2010-04-16 09:05:35 +00:00
|
|
|
</body>
|
|
|
|
</html>
|