Author: pyaschenko
Date: 2010-07-22 07:55:06 -0400 (Thu, 22 Jul 2010)
New Revision: 18190
Modified:
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoComplete.ecss
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
fetchValue fixed
Modified:
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoComplete.ecss
===================================================================
---
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoComplete.ecss 2010-07-22
04:47:58 UTC (rev 18189)
+++
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoComplete.ecss 2010-07-22
11:55:06 UTC (rev 18190)
@@ -1,5 +1,5 @@
.cb_field_width {
- width: 100px;
+ width: 200px;
}
.cb_list_width {
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
04:47:58 UTC (rev 18189)
+++
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoComplete.js 2010-07-22
11:55:06 UTC (rev 18190)
@@ -6,16 +6,7 @@
this.cache = {}
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 = [];
@@ -63,15 +54,19 @@
(function ($, rf) {
+ /*
+ * TODO: add user's event handlers call from options
+ * TODO: add fire events
+ */
+
rf.ui = rf.ui || {};
// Constructor definition
rf.ui.AutoComplete = function(componentId, fieldId, options) {
- this.namespace = "."+rf.Event.createNamespace(this.name, this.componentId);
+ this.namespace = "."+rf.Event.createNamespace(this.name, this.id);
this.options = {};
// call constructor of parent class
- $super.constructor.call(this, componentId+ID.SELECT, fieldId, options);
+ $super.constructor.call(this, componentId, componentId+ID.SELECT, fieldId, options);
this.attachToDom(componentId);
- this.componentId = componentId;
this.options = $.extend(this.options, defaultOptions, options);
this.inputValue = this.getInputValue();
this.index = -1;
@@ -100,8 +95,6 @@
ITEMS:'Items'
};
- var DATA_TAG = "value";
-
var REGEXP_TRIM = /^[\n\s]*(.*)[\n\s]*$/;
var getData = function (nodeList) {
@@ -113,7 +106,7 @@
}
var bindEventHandlers = function () {
- rf.Event.bind(rf.getDomElement(this.componentId+ID.ITEMS).parentNode,
"click"+this.namespace+" mouseover"+this.namespace, onMouseAction,
this);
+ rf.Event.bind(rf.getDomElement(this.id+ID.ITEMS).parentNode,
"click"+this.namespace+" mouseover"+this.namespace, onMouseAction,
this);
};
var onMouseAction = function(event) {
@@ -135,8 +128,13 @@
};
var updateItemsList = function (value, fetchValues) {
- this.items =
$(rf.getDomElement(this.componentId+ID.ITEMS)).find(".rf-ac-i");
- this.cache = new rf.utils.Cache(value, this.items, fetchValues || getData);
+ 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);
+ }
};
var scrollToSelectedItem = function() {
@@ -168,7 +166,7 @@
var _this = this;
var ajaxSuccess = function (event) {
- updateItemsList.call(_this, _this.inputValue, event.componentData);
+ updateItemsList.call(_this, _this.inputValue, event.componentData &&
event.componentData[_this.id]);
if (_this.options.selectFirst) {
_this.selectItem(0);
}
@@ -181,9 +179,9 @@
this.isFirstAjax = false;
//caution: JSF submits inputs with empty names causing "WARNING: Parameters:
Invalid chunk ignored." in Tomcat log
var params = {};
- params[this.componentId + ".ajax"] = "1";
+ params[this.id + ".ajax"] = "1";
- rf.ajax(this.componentId, event, {parameters: params, error: ajaxError,
complete:ajaxSuccess});
+ rf.ajax(this.id, event, {parameters: params, error: ajaxError, complete:ajaxSuccess});
};
/*
@@ -235,7 +233,7 @@
}
// TODO: ajax call here if needed
- if (( value.toLowerCase().indexOf(this.cache.key.toLowerCase())!=0 ||
this.inputValue.length==0) &&
+ if ((!this.cache || value.toLowerCase().indexOf(this.cache.key.toLowerCase())!=0 ||
this.inputValue.length==0) &&
value.length>=this.options.minChars) {
this.inputValue = value;
this.options.ajaxMode && callAjax.call(this, event);
@@ -245,7 +243,7 @@
var newItems = this.cache.getItems(value);
this.items = $(newItems);
//TODO: works only with simple markup, not with <tr>
- $(rf.getDomElement(this.componentId+ID.ITEMS)).empty().append(newItems);
+ $(rf.getDomElement(this.id+ID.ITEMS)).empty().append(newItems);
this.index = -1;
this.inputValue = value;
if (this.options.selectFirst) {
@@ -256,7 +254,7 @@
var getSelectedItemValue = function () {
if ( this.index>=0) {
var element = this.items.eq(this.index);
- return element.data(DATA_TAG) || getData(element)[0];
+ return element.parent().data()[this.index] || getData(element)[0];
}
return undefined;
};
@@ -313,7 +311,7 @@
//TODO: add all unbind
this.items = null;
this.cache = null;
- rf.Event.unbind(rf.getDomElement(this.componentId+ID.ITEMS).parentNode,
this.namespace);
+ rf.Event.unbind(rf.getDomElement(this.id+ID.ITEMS).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
04:47:58 UTC (rev 18189)
+++
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoCompleteBase.js 2010-07-22
11:55:06 UTC (rev 18190)
@@ -40,9 +40,9 @@
rf.ui = rf.ui || {};
// Constructor definition
- rf.ui.AutoCompleteBase = function(selectId, fieldId, options) {
+ rf.ui.AutoCompleteBase = function(componentId, selectId, fieldId, options) {
// call constructor of parent class
- $super.constructor.call(this, selectId);
+ $super.constructor.call(this, componentId);
this.selectId = selectId;
this.fieldId = fieldId;
this.options = $.extend({}, defaultOptions, options);