Author: pyaschenko
Date: 2010-07-29 12:16:36 -0400 (Thu, 29 Jul 2010)
New Revision: 18283
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
tokens fixes
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-29
16:13:37 UTC (rev 18282)
+++
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoComplete.js 2010-07-29
16:16:36 UTC (rev 18283)
@@ -89,7 +89,7 @@
var defaultOptions = {
selectedItemClass:'cb_select',
- autoFill:false,
+ autoFill:true,
minChars:1,
selectFirst:true,
ajaxMode:true,
@@ -121,6 +121,7 @@
var escapedTokens = this.options.tokens.split('').join("\\");
REGEXP_TOKEN_LEFT = new RegExp('[^'+escapedTokens+']+$','i');
REGEXP_TOKEN_RIGHT = new RegExp('['+escapedTokens+']','i');
+ this.hasSpaceToken = this.options.tokens.indexOf(' ')!=-1;
};
};
@@ -139,7 +140,7 @@
selectItem.call(this, index);
}
} else {
- this.__changeValue(event, getSelectedItemValue.call(this));
+ this.__onChangeValue(event, getSelectedItemValue.call(this));
rf.Selection.setCaretTo(rf.getDomElement(this.fieldId));
this.hide(event);
}
@@ -174,7 +175,8 @@
var field = rf.getDomElement(this.fieldId);
var start = rf.Selection.getStart(field);
this.setInputValue(inputValue + value.substring(inputValue.length));
- rf.Selection.set(field, start, field.value.length);
+ var end = start+value.length - inputValue.length;
+ rf.Selection.set(field, start, end);
}
};
@@ -203,10 +205,6 @@
rf.ajax(this.id, event, {parameters: params, error: ajaxError, complete:ajaxSuccess});
};
- /*
- * public API functions definition
- */
-
var selectItem = function(index, isOffset, noAutoFill) {
if (this.items.length==0) return;
@@ -240,7 +238,7 @@
!noAutoFill && autoFill.call(this, this.value,
getSelectedItemValue.call(this));
};
- var changeValue = function (event, value) {
+ var onChangeValue = function (event, value) {
selectItem.call(this);
// value is undefined if called from AutoCompleteBase onChange
@@ -278,6 +276,7 @@
};
var getSubValue = function () {
+ //TODO: add posibility to use space chars before and after tokens if space not a token
char
if (this.useTokens) {
var field = rf.getDomElement(this.fieldId);
var value = field.value;
@@ -302,16 +301,21 @@
var updateInputValue = function (value) {
var field = rf.getDomElement(this.fieldId);
var inputValue = field.value;
+
var cursorPosition = rf.Selection.getStart(field);
var beforeCursorStr = inputValue.substring(0, cursorPosition);
var afterCursorStr = inputValue.substring(cursorPosition);
+
var pos = beforeCursorStr.search(REGEXP_TOKEN_LEFT);
var startPos = pos!=-1 ? pos : 0;
pos = afterCursorStr.search(REGEXP_TOKEN_RIGHT);
var endPos = pos!=-1 ? pos : inputValue.length;
+
+ var beginNewValue = inputValue.substring(0, startPos) + value;
+ cursorPosition = beginNewValue.length;
+ field.value = beginNewValue + afterCursorStr.substring(endPos);
field.focus();
- field.value = inputValue.substring(0, startPos) + value +
afterCursorStr.substring(endPos);
- rf.Selection.setCaretTo(field, cursorPosition+endPos);
+ rf.Selection.setCaretTo(field, cursorPosition);
return field.value;
};
@@ -327,7 +331,6 @@
/*
* Protected methods
*/
- __changeValue: changeValue,
__updateState: function () {
var subValue = this.__getSubValue();
// called from onShow method, not actually value changed
@@ -344,6 +347,7 @@
return $super.__updateInputValue.call(this, value);
}
},
+ __onChangeValue: onChangeValue,
/*
* Override abstract protected methods
*/
@@ -362,10 +366,10 @@
__onBeforeShow: function (event) {
},
__onEnter: function (event) {
- this.__changeValue(event, getSelectedItemValue.call(this));
- rf.getDomElement(this.fieldId).blur();
- rf.Selection.setCaretTo(rf.getDomElement(this.fieldId));
- rf.getDomElement(this.fieldId).focus();
+ this.__onChangeValue(event, getSelectedItemValue.call(this));
+ //rf.getDomElement(this.fieldId).blur();
+ //rf.Selection.setCaretTo(rf.getDomElement(this.fieldId));
+ //rf.getDomElement(this.fieldId).focus();
},
__onShow: function (event) {
if (event.which != rf.KEYS.BACKSPACE && this.items &&
this.items.length>0) {
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-29
16:13:37 UTC (rev 18282)
+++
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoCompleteBase.js 2010-07-29
16:16:36 UTC (rev 18283)
@@ -133,9 +133,10 @@
var value = this.getInputValue();
var flag = value != this.currentValue;
//TODO: is it needed to chesk keys?
+ //TODO: we need to set value when autoFill used when LEFT or RIGHT was pressed
if (event.which == rf.KEYS.LEFT || event.which == rf.KEYS.RIGHT || flag) {
if (flag) {
- this.__changeValue(event);
+ this.__onChangeValue(event);
onShow.call(this, event);
}
}
@@ -176,15 +177,11 @@
break;
case rf.KEYS.TAB:
case rf.KEYS.RETURN:
- //TODO draft code, merge with code from combobox.js
+
event.preventDefault();
this.__onEnter(event);
- /*if( selectCurrentItem() ) {
- event.preventDefault();
- //TODO: bind form submit event handler to cancel form submit under the opera
- //cancelSubmit = true;
- return false;
- }*/
+ //TODO: bind form submit event handler to cancel form submit under the opera
+ //cancelSubmit = true;
this.hide();
return false;
break;
@@ -267,6 +264,8 @@
/*
* abstract protected methods
*/
+ __onChangeValue: function (event) {
+ },
__onKeyUp: function () {
},
__onKeyDown: function () {