Author: pyaschenko
Date: 2010-07-09 13:33:53 -0400 (Fri, 09 Jul 2010)
New Revision: 17791
Modified:
root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces-selection.js
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/ComboBox.js
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/SelectBase.js
Log:
https://jira.jboss.org/browse/RF-8875
Modified:
root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces-selection.js
===================================================================
---
root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces-selection.js 2010-07-09
16:47:57 UTC (rev 17790)
+++
root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces-selection.js 2010-07-09
17:33:53 UTC (rev 17791)
@@ -40,6 +40,7 @@
richfaces.Selection.setCaretTo = function (field, pos)
{
+ if (!pos) pos = field.value.length;
richfaces.Selection.set(field, pos, pos);
}
})(window.RichFaces || (window.RichFaces={}));
\ No newline at end of file
Modified:
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/ComboBox.js
===================================================================
---
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/ComboBox.js 2010-07-09
16:47:57 UTC (rev 17790)
+++
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/ComboBox.js 2010-07-09
17:33:53 UTC (rev 17791)
@@ -64,7 +64,7 @@
$p.attachToDom.call(this, componentId);
this.componentId = componentId;
this.options = $.extend(this.options, defaultOptions, options);
- this.inputValue = rf.getDomElement(this.fieldId).value;
+ this.inputValue = this.getInputValue();
this.index = -1;
this.isFirstAjax = true;
bindEventHandlers.call(this);
@@ -103,17 +103,23 @@
}
var bindEventHandlers = function () {
- rf.Event.bind(rf.getDomElement(this.componentId+ID.ITEMS).parentNode,
"mouseover"+this.namespace, onMouseOver, this);
+ rf.Event.bind(rf.getDomElement(this.componentId+ID.ITEMS).parentNode,
"click"+this.namespace+" mouseover"+this.namespace, onMouseAction,
this);
};
- var onMouseOver = function(event) {
- console && console.log && console.log("mouseOver");
+ var onMouseAction = function(event) {
+ console && console.log && console.log("mouseAction:" +
event.type);
var element = $(event.target).closest(".rf-ac-i",
event.currentTarget).get(0);
if (element) {
- var index = this.items.index(element);
- if (index!=this.index) {
- this.selectItem(index);
+ if (event.type=="mouseover") {
+ var index = this.items.index(element);
+ if (index!=this.index) {
+ this.selectItem(index);
+ }
+ } else {
+ this.changeValue(event, this.getSelectedItemValue());
+ rf.Selection.setCaretTo(rf.getDomElement(this.fieldId));
+ this.hide(event);
}
}
};
@@ -217,8 +223,27 @@
item.addClass(this.options.selectedItemClass);
scrollToSelectedItem.call(this);
- !noAutoFill && autoFill.call(this, this.inputValue, getData(item)[0]);
+ !noAutoFill && autoFill.call(this, this.inputValue,
this.getSelectedItemValue());
},
+
+ // value - string or index number
+ /*setInputValue: function (value) {
+ var type = typeof value;
+ var input = rf.getDomElement(this.fieldId);
+
+ if (type == "string") {
+ this.inputValue = value;
+ $super.setInputValue.call(this, value);
+ } else {
+ if (type != "number") {
+ value = this.index;
+ }
+ if (value >=0 && value < this.items.length) {
+ this.inputValue = getData(this.items.eq(this.index))[0];
+ $super.setInputValue.call(this, this.inputValue);
+ }
+ }
+ },*/
selectPrevItem: function () {
this.selectItem(-1, true);
@@ -247,7 +272,7 @@
}
// TODO: ajax call here if needed
- if (( value.indexOf(this.cache.key)!=0 || this.inputValue.length==0) &&
+ if (( 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);
@@ -264,6 +289,13 @@
this.selectItem(0, false, event.which == rf.KEYS.BACKSPACE);
}
},
+
+ getSelectedItemValue: function () {
+ if ( this.index>=0) {
+ return getData(this.items.eq(this.index))[0];
+ }
+ return undefined;
+ },
onShow: function (event) {
if (this.items && this.items.length>0) {
Modified:
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/SelectBase.js
===================================================================
---
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/SelectBase.js 2010-07-09
16:47:57 UTC (rev 17790)
+++
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/SelectBase.js 2010-07-09
17:33:53 UTC (rev 17791)
@@ -78,14 +78,15 @@
rf.Event.bindById(this.fieldId, inputEventHandlers, this);
inputEventHandlers = {};
- inputEventHandlers["click"+this.namespace] = onSelectClick;
+ //inputEventHandlers["click"+this.namespace] = onSelectClick;
inputEventHandlers["mousedown"+this.namespace] = onSelectMouseDown;
inputEventHandlers["mouseup"+this.namespace] = onSelectMouseUp;
rf.Event.bindById(this.selectId, inputEventHandlers, this);
}
- var onSelectClick = function () {
- };
+ /*var onSelectClick = function () {
+ };*/
+
var onSelectMouseDown = function () {
this.isMouseDown = true;
//console && console.log && console.log("onMouseDown");
@@ -186,7 +187,12 @@
break;
case rf.KEYS.TAB:
case rf.KEYS.RETURN:
+ //TODO draft code, merge with code from combobox.js
event.preventDefault();
+ this.changeValue(event, this.getSelectedItemValue());
+ rf.getDomElement(this.fieldId).blur();
+ rf.Selection.setCaretTo(rf.getDomElement(this.fieldId));
+ rf.getDomElement(this.fieldId).focus();
/*if( selectCurrentItem() ) {
event.preventDefault();
//TODO: bind form submit event handler to cancel form submit under the opera
@@ -194,10 +200,11 @@
return false;
}*/
this.hide();
+ return false;
break;
- case rf.KEYS.ESC:
+ /*case rf.KEYS.ESC:
this.hide();
- break;
+ break;*/
default:
if (!this.options.selectOnly) {
var _this = this;
@@ -255,9 +262,14 @@
onBeforeShow: function () {
},
getInputValue: function () {
- var value = this.fieldId ? rf.getDomElement(this.fieldId).value : undefined;
- return value;
+ return this.fieldId ? rf.getDomElement(this.fieldId).value : undefined;;
+ },
+ getSelectedItemValue: function () {
}
+ /*setInputValue: function (value) {
+ this.currentValue = value;
+ rf.getDomElement(this.fieldId).value = value;
+ }*/
};
})());