Created
October 12, 2010 01:44
-
-
Save ghinch/621522 to your computer and use it in GitHub Desktop.
This file contains 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> | |
<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