Skip to content

Instantly share code, notes, and snippets.

@benediktarnold
Created May 21, 2012 12:23
Show Gist options
  • Select an option

  • Save benediktarnold/2762093 to your computer and use it in GitHub Desktop.

Select an option

Save benediktarnold/2762093 to your computer and use it in GitHub Desktop.
YUI3 Example: How to use autocomplete-list as a combobox
<!doctype html>
<html>
<head>
<title>
</title>
<script src="http://yui.yahooapis.com/3.5.1/build/yui/yui-min.js">
</script>
<link rel="stylesheet" type="text/css" href="css/combo.css">
</head>
<body class="yui3-skin-sam">
<div class="combo">
<input type="text">
</input>
<button>
...
</button>
</div>
</body>
<script>
// Create a new YUI instance and populate it with the required modules.
YUI({
filter: 'RAW'
}).use(['autocomplete', 'autocomplete-filters', 'autocomplete-highlighters', 'event-outside'], function(Y) {
var ac = new Y.AutoCompleteList({
inputNode: '.combo input',
source: ['friends', 'Romans', 'countrymen', 'bla', 'blub', 'blablub'],
render: true,
minQueryLength: 0,
tabSelect: true,
activateFirstItem: true
});
Y.one('.combo button').on('click', function(e) {
console.log(ac);
e.stopPropagation();
if (ac.get('visible')) {
ac.hide();
} else {
ac.sendRequest();
ac.show();
}
});
});
</script>
</html>
@markward

markward commented Jul 3, 2013

Copy link
Copy Markdown

Very useful, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment