Author: pyaschenko
Date: 2010-07-20 12:36:02 -0400 (Tue, 20 Jul 2010)
New Revision: 18162
Modified:
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoComplete.js
Log:
https://jira.jboss.org/browse/RF-8875
fetch value was added
Modified:
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoComplete.js
===================================================================
---
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoComplete.js 2010-07-20
15:17:30 UTC (rev 18161)
+++
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoComplete.js 2010-07-20
16:36:02 UTC (rev 18162)
@@ -1,12 +1,21 @@
(function ($, rf) {
rf.utils = rf.utils || {};
- rf.utils.Cache = function (data, options) {
- this.key = options.key;
+ rf.utils.Cache = function (key, items, values) {
+ this.key = key;
this.cache = {}
- this.cache[this.key] = data || [];
- this.values = options.parse && options.parse(data) || this.cache[this.key];
+ this.cache[this.key] = items || [];
+ this.values = typeof values != "function" ? values || this.cache[this.key] :
values(items);
+ updateItemsData(items, this.values);
};
+
+ var updateItemsData = function (items, values) {
+ if (items.first()["nodeType"]) {
+ items.each(function(index){
+ this.data("value", values[index]);
+ });
+ }
+ }
var getItems = function (key) {
var newCache = [];
@@ -91,6 +100,8 @@
ITEMS:'Items'
};
+ var DATA_TAG = "value";
+
var REGEXP_TRIM = /^[\n\s]*(.*)[\n\s]*$/;
var getData = function (nodeList) {
@@ -123,12 +134,9 @@
}
};
- var updateItemsList = function (value) {
+ var updateItemsList = function (value, fetchValues) {
this.items =
$(rf.getDomElement(this.componentId+ID.ITEMS)).find(".rf-ac-i");
- this.cache = new rf.utils.Cache(this.items, {
- parse: getData,
- key: value
- });
+ this.cache = new rf.utils.Cache(value, this.items, fetchValues || getData);
};
var scrollToSelectedItem = function() {
@@ -159,8 +167,8 @@
var callAjax = function(event) {
var _this = this;
- var ajaxSuccess = function () {
- updateItemsList.call(_this, _this.inputValue);
+ var ajaxSuccess = function (event) {
+ updateItemsList.call(_this, _this.inputValue, event.componentData);
if (_this.options.selectFirst) {
_this.selectItem(0);
}
@@ -278,7 +286,8 @@
getSelectedItemValue: function () {
if ( this.index>=0) {
- return getData(this.items.eq(this.index))[0];
+ var element = this.items.eq(this.index);
+ return element.data(DATA_TAG) || getData(element)[0];
}
return undefined;
},