Author: pyaschenko
Date: 2008-03-11 09:52:24 -0400 (Tue, 11 Mar 2008)
New Revision: 6688
Modified:
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js
Log:
RF-1774
Correct values insertion was added when tokens are used (draft)
Modified:
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js
===================================================================
---
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js 2008-03-11
13:39:50 UTC (rev 6687)
+++
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js 2008-03-11
13:52:24 UTC (rev 6688)
@@ -585,7 +585,7 @@
} else
value = Element.collectTextNodesIgnoreClass(selectedElement,
'informal');
- var lastTokenPos = this.findLastToken();
+ /*var lastTokenPos = this.findLastToken();
if (lastTokenPos != -1) {
var newValue = this.element.value.substr(0, lastTokenPos + 1);
var whitespace = this.element.value.substr(lastTokenPos
@@ -595,14 +595,15 @@
this.element.value = newValue + value;
} else {
this.element.value = value;
- }
+ }*/
+ this.insertValue(value);
this.oldValue = this.element.value;
this.element.focus();
if (this.options.afterUpdateElement)
this.options.afterUpdateElement(this.element, selectedElement);
},
-
+
updateChoices: function(choices) {
if (!this.changed && this.hasFocus) {
if (choices) {
@@ -663,6 +664,24 @@
LOG.debug("Observer event occurs");
this.changed = false;
var oldValue = this.element.value;
+
+ if (this.oldValue!=oldValue)
+ {
+ this.endPosition = 0;
+ this.startPosition = 0;
+ var tokens = this.options.tokens.join('');
+ while (this.oldValue[this.endPosition]==oldValue[this.endPosition])
+ {
+ if (tokens.indexOf(oldValue[this.endPosition])!=-1) this.startPosition =
this.endPosition+1;
+ this.endPosition++;
+ }
+ if (oldValue.length>this.oldValue.length &&
this.startPosition!=this.endPosition &&
tokens.indexOf(oldValue[this.endPosition])!=-1) this.startPosition = ++this.endPosition;
+
+ while (oldValue[this.startPosition]==' ') this.startPosition++;
+ while (this.endPosition<oldValue.length &&
tokens.indexOf(oldValue[this.endPosition])==-1) this.endPosition++;
+ //alert(this.startPosition + ","+ this.endPosition+":
"+oldValue.substring(this.startPosition, this.endPosition));
+ }
+
if (this.getToken().length >= this.options.minChars) {
LOG.debug("Call data for update choices");
if ((event.keyCode == Event.KEY_DOWN || this.oldValue != oldValue) &&
oldValue.length > 0) {
@@ -677,7 +696,7 @@
this.observerHandle = null;
},
- getToken: function() {
+ /*getToken: function() {
var tokenPos = this.findLastToken();
if (tokenPos != -1)
var ret = this.element.value.substr(tokenPos
@@ -686,8 +705,34 @@
var ret = this.element.value;
return /\n/.test(ret) ? '' : ret;
+ },*/
+
+ insertValue: function(value)
+ {
+ //if (this.startPosition && this.endPosition)
+ //{
+ var startStr = this.element.value.substr(0,this.startPosition);
+ var endStr = this.element.value.substr(this.endPosition);
+ var whitespace = this.element.value.substring(this.startPosition,
this.endPosition).match(/\s+$/);
+ if (whitespace)
+ endStr = whitespace[0] + endStr;
+ this.element.value = startStr + value + endStr;
+ //}
+ /*else
+ {
+ this.element.value = value;
+ }*/
},
+ getToken: function() {
+ //if (this.startPosition && this.endPosition)
+ var ret = this.element.value.substring(this.startPosition,
this.endPosition).replace(/^\s+/, '').replace(/\s+$/, '');
+ /*else
+ var ret = this.element.value;*/
+
+ return /\n/.test(ret) ? '' : ret;
+ }/*,
+
findLastToken: function() {
var lastTokenPos = -1;
@@ -697,7 +742,7 @@
lastTokenPos = thisTokenPos;
}
return lastTokenPos;
- }
+ }*/
}
Show replies by date