Author: pyaschenko
Date: 2010-07-22 11:35:18 -0400 (Thu, 22 Jul 2010)
New Revision: 18198
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/AutoCompleteBase.js
Log:
https://jira.jboss.org/browse/RF-8875
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-22
15:33:47 UTC (rev 18197)
+++
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoComplete.js 2010-07-22
15:35:18 UTC (rev 18198)
@@ -39,13 +39,18 @@
return newCache;
};
+ var getItemValue = function (item) {
+ return this.values[this.cache[this.key].index(item)];
+ };
+
var isCached = function (key) {
return this.cache[key];
- }
+ };
$.extend(rf.utils.Cache.prototype, (function () {
return {
getItems: getItems,
+ getItemValue: getItemValue,
isCached: isCached
};
})());
@@ -87,7 +92,8 @@
minChars:1,
selectFirst:true,
ajaxMode:true,
- attachToBody:true
+ attachToBody:true,
+ tokens: ", "
};
var ID = {
@@ -130,9 +136,6 @@
var updateItemsList = function (value, fetchValues) {
this.items = $(rf.getDomElement(this.id+ID.ITEMS)).find(".rf-ac-i");
if (this.items.length>0) {
- var parent = this.items.first().parent();
- parent.data(fetchValues);
-
this.cache = new rf.utils.Cache(value, this.items, fetchValues || getData);
}
};
@@ -142,13 +145,13 @@
this.items.slice(0, this.index).each(function() {
offset += this.offsetHeight;
});
- var itemsContainer = this.items.first().parent().parent();
- if(offset < itemsContainer.scrollTop()) {
- itemsContainer.scrollTop(offset);
+ var parentContainer = $(rf.getDomElement(this.id+ID.ITEMS)).parent();
+ if(offset < parentContainer.scrollTop()) {
+ parentContainer.scrollTop(offset);
} else {
offset+=this.items.get(this.index).offsetHeight;
- if(offset - itemsContainer.scrollTop() > itemsContainer.get(0).clientHeight)
{
- itemsContainer.scrollTop(offset - itemsContainer.innerHeight());
+ if(offset - parentContainer.scrollTop() >
parentContainer.get(0).clientHeight) {
+ parentContainer.scrollTop(offset - parentContainer.innerHeight());
}
}
};
@@ -164,6 +167,8 @@
var callAjax = function(event) {
+ $(rf.getDomElement(this.id+ID.ITEMS)).removeData().empty();
+
var _this = this;
var ajaxSuccess = function (event) {
updateItemsList.call(_this, _this.inputValue, event.componentData &&
event.componentData[_this.id]);
@@ -173,7 +178,7 @@
}
var ajaxError = function () {
- alert("error");
+ //alert("error");
}
this.isFirstAjax = false;
@@ -254,7 +259,7 @@
var getSelectedItemValue = function () {
if ( this.index>=0) {
var element = this.items.eq(this.index);
- return element.parent().data()[this.index] || getData(element)[0];
+ return this.cache.getItemValue(element);
}
return undefined;
};
@@ -311,7 +316,9 @@
//TODO: add all unbind
this.items = null;
this.cache = null;
- rf.Event.unbind(rf.getDomElement(this.id+ID.ITEMS).parentNode, this.namespace);
+ var itemsContainer = rf.getDomElement(this.id+ID.ITEMS);
+ $(itemsContainer).removeData();
+ rf.Event.unbind(itemsContainer.parentNode, this.namespace);
$super.destroy.call(this);
}
};
Modified:
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoCompleteBase.js
===================================================================
---
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoCompleteBase.js 2010-07-22
15:33:47 UTC (rev 18197)
+++
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoCompleteBase.js 2010-07-22
15:35:18 UTC (rev 18198)
@@ -62,12 +62,16 @@
};
var bindEventHandlers = function() {
+
+ var inputEventHandlers = {};
+
if (this.options.buttonId) {
- rf.Event.bindById(this.options.buttonId, "mousedown"+this.namespace,
onButtonShow, this);
- rf.Event.bindById(this.options.buttonId, "mouseup"+this.namespace,
onSelectMouseUp, this);
+ inputEventHandlers["mousedown"+this.namespace] = onButtonShow;
+ inputEventHandlers["mouseup"+this.namespace] = onSelectMouseUp;
+ rf.Event.bindById(this.options.buttonId, inputEventHandlers, this);
}
- var inputEventHandlers = {};
+ inputEventHandlers = {};
inputEventHandlers["focus"+this.namespace] = onFocus;
inputEventHandlers["blur"+this.namespace] = onBlur;
inputEventHandlers["click"+this.namespace] = onClick;
@@ -75,7 +79,6 @@
rf.Event.bindById(this.fieldId, inputEventHandlers, this);
inputEventHandlers = {};
- //inputEventHandlers["click"+this.namespace] = onSelectClick;
inputEventHandlers["mousedown"+this.namespace] = onSelectMouseDown;
inputEventHandlers["mouseup"+this.namespace] = onSelectMouseUp;
rf.Event.bindById(this.selectId, inputEventHandlers, this);
@@ -288,7 +291,7 @@
rf.Event.unbindScrollEventHandlers(this.scrollElements, this);
this.scrollElements = null;
}
- rf.Event.unbindById(this.options.buttonId, this.namespace);
+ this.options.buttonId && rf.Event.unbindById(this.options.buttonId,
this.namespace);
rf.Event.unbindById(this.fieldId, this.namespace);
rf.Event.unbindById(this.selectId, this.namespace);
$super.destroy.call(this);