[英]How do I change YUI Autocomplete textfield Value population Options?
Data: 数据:
JACKSON, MS 39212|39212
BAINVILLE, MT 59212|59212
CROOKSTON, NE 69212|69212
COLUMBIA, SC 29212|29212
SPOKANE, WA 99212|99212
Code: 码:
<form method="GET" target="_blank">
<fieldset><legend>remote example</legend>
<label for="myRemoteInput">Enter a state:</label>
<div id="myRemoteAutoComplete">
<input id="myRemoteInput" name="myRemoteInput" type="text">
<div id="myRemoteContainer"></div>
</div>
</fieldset>
<input type="submit" />
</form>
<script type="text/javascript">
YAHOO.example.BasicRemote = function() {
var oRDS = new YAHOO.util.XHRDataSource("data.php");
oRDS.responseType = YAHOO.util.XHRDataSource.TYPE_TEXT;
oRDS.responseSchema = {
recordDelim: "\n",
fieldDelim: "|"
};
oRDS.maxCacheEntries = 5;
var oRAC = new YAHOO.widget.AutoComplete("myRemoteInput"
, "myRemoteContainer"
, oRDS
, {minQueryLength: 2,maxResultsDisplayed: 25, forceSelection: true});
return {
oRDS: oRDS,
oRAC: oRAC
};
}();
</script>
Scenario: I want to display the autocomplete widget with the City, ST zip values, however, the form field myRemoteInput always populates with the selected City, ST zip value. 场景:我想显示带有City,ST邮政编码值的自动完成窗口小部件,但是,表单字段myRemoteInput始终使用选定的City,ST邮政编码值填充。
Question: How do I populate the form field myRemoteInput value with the zipcode when a user selects the City, ST zip value from the autocomplete drop down? 问题:当用户从自动完成下拉列表中选择城市,ST邮政编码值时,如何用邮政编码填充表单字段myRemoteInput值?
the custom event itemSelectEvent might be what you are looking for. 自定义事件itemSelectEvent可能就是您想要的。 I have never used it myself, but it could be something like 我本人从未使用过它,但是可能像
oRAC.itemSelectEvent.subscribe(onItemSelect);
function onItemSelect(oSelf , elItem , oData) {
var locationData = oData[0];
// Now parse location data and put only the ZIP code back into oData[0]
}
Got this from How do I change YUI Autocomplete textfield Value population Options? 从如何更改YUI自动完成文本字段值填充选项中获得了此信息? and adapted it a bit. 并对其进行了调整。 I have no idea if this works, but it might get you started. 我不知道这是否可行,但它可能会让您入门。
I guess you know the API, but just in case: http://developer.yahoo.com/yui/docs/YAHOO.widget.AutoComplete.html . 我想您知道API,但以防万一: http : //developer.yahoo.com/yui/docs/YAHOO.widget.AutoComplete.html 。
hth hth
Tom 汤姆
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.