Skip to content

Instantly share code, notes, and snippets.

@ghinch
Created October 12, 2010 01:44
Show Gist options
  • Save ghinch/621522 to your computer and use it in GitHub Desktop.
Save ghinch/621522 to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<title>test</title>
<script type="text/javascript" src="js/yui/yui-min.js"></script>
</head>
<body class="yui3-skin-sam">
<select id="typeChoice">
<option>Select one</option>
<option value="fruits">Fruits</option>
<option value="veg">Vegetables</option>
<option value="meats">Meats</option>
</select>
<input id="acInput">
<script type="text/javascript">
/*******
yui3/build checkout is symlinked to ./js
*******/
YUI({
combine : false,
base : 'js/',
root : '',
filter: 'raw'
}).use('datasource-local', 'datasource-arrayschema', 'autocomplete', 'autocomplete-filters',
function (Y) {
var dataSets = {
fruits : [
'Apples',
'Oranges',
'Bananas'
],
veg : [
'Lettuce',
'Carrots',
'Cucumber'
],
meats : [
'Beef',
'Chicken',
'Pork'
]
};
var ds = new Y.DataSource.Local({
plugins : [
{fn : Y.DataSourceArraySchema}
]
});
var ac = new Y.AutoComplete({
inputNode : '#acInput',
source : ds,
resultFilters : [
Y.AutoCompleteFilters.charMatch
],
minQueryLength : 0,
render : true
});
var iNode = ac.get('inputNode')
iNode.set('disabled', true);
Y.one('#typeChoice').on('change', function (e) {
var val = e.target.get('value');
iNode.set('value', '');
if (val && val in dataSets) {
iNode.set('disabled', false);
ds.set('source', dataSets[val]);
iNode.focus();
ac.sendRequest('');
} else {
iNode.set('disabled', true);
}
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment