Author: pyaschenko
Date: 2010-06-30 11:52:20 -0400 (Wed, 30 Jun 2010)
New Revision: 17685
Modified:
root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/ComboBox.js
root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/SelectBase.js
root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/richfaces-selection.js
Log:
https://jira.jboss.org/browse/RF-8875
Modified:
root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/ComboBox.js
===================================================================
---
root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/ComboBox.js 2010-06-30
11:42:30 UTC (rev 17684)
+++
root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/ComboBox.js 2010-06-30
15:52:20 UTC (rev 17685)
@@ -24,7 +24,7 @@
}
if ((!this.lastKey || key.indexOf(this.lastKey)!=0) && newCache.length > 0)
{
- console && console.log && console.log("added
key:"+key+" length:" + newCache.length)
+ //console && console.log && console.log("added
key:"+key+" length:" + newCache.length)
this.cache[key] = newCache;
if (newCache.length==1) {
this.lastKey = key;
@@ -132,7 +132,7 @@
var autoFill = function (inputValue, value) {
if( this.options.autoFill) {
var field = rf.getDomElement(this.fieldId);
- field.value = field.value + value.substring(inputValue.length);
+ field.value = inputValue + value.substring(inputValue.length);
rf.Selection.set(field, inputValue.length, field.value.length);
}
};
@@ -149,7 +149,7 @@
return this.namespace;
},
- selectItem: function(index, isOffset) {
+ selectItem: function(index, isOffset, noAutoFill) {
if (this.items.length==0) return;
if (this.index!=-1) {
@@ -176,9 +176,11 @@
}
this.index = index;
}
- this.items.eq(this.index).addClass(this.options.selectedItemClass);
+ var item = this.items.eq(this.index);
+ item.addClass(this.options.selectedItemClass);
scrollToSelectedItem.call(this);
+ !noAutoFill && autoFill.call(this, this.newValue, item.text());
},
selectPrevItem: function () {
@@ -196,24 +198,19 @@
onBeforeShow: function (event) {
},
- onChange: function (event, value) {
+ changeValue: function (event, value) {
// TODO: ajax call here if needed
-
this.selectItem();
var newItems = this.cache.getItems(value);
this.items = $(newItems);
$(rf.getDomElement(this.componentId+ID.ITEMS)).empty().append(newItems);
this.index = -1;
- this.selectItem(0);
- // getFirstValue
- $(this.items).first().text();
- if (event.which != rf.KEYS.BACKSPACE) {
- autoFill.call(this, value, $(this.items).first().text());
- }
+ this.newValue = value;
+ this.selectItem(0, false, event.which == rf.KEYS.BACKSPACE);
},
- onShow: function () {
+ onShow: function (event) {
if (this.items && this.items.length>0) {
//??TODO it's nessesary only if not changed value
this.selectItem(0);
Modified:
root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/SelectBase.js
===================================================================
---
root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/SelectBase.js 2010-06-30
11:42:30 UTC (rev 17684)
+++
root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/SelectBase.js 2010-06-30
15:52:20 UTC (rev 17685)
@@ -48,7 +48,7 @@
this.fieldId = fieldId;
this.options = $.extend({}, defaultOptions, options);
this.namespace = this.namespace || "."+rf.Event.createNamespace(this.name,
this.selectId);
- this.currentValue = this.getCurrentValue();
+ this.currentValue = this.getInputValue();
bindEventHandlers.call(this);
};
@@ -133,16 +133,15 @@
};
var onChange = function (event) {
- var value = this.getCurrentValue();
+ var value = this.getInputValue();
var flag = value != this.currentValue;
if (event.which == rf.KEYS.LEFT || event.which == rf.KEYS.RIGHT || flag) {
- // TODO: call onchange
- if (flag && !this.isVisible) {
- this.show();
- }
if (flag) {
- this.onChange(event, value);
+ this.changeValue(event, value);
this.currentValue = value;
+ if (!this.isVisible) {
+ this.show();
+ }
}
}
}
@@ -247,7 +246,7 @@
},
onBeforeShow: function () {
},
- getCurrentValue: function () {
+ getInputValue: function () {
var value = this.fieldId ? rf.getDomElement(this.fieldId).value : undefined;
return value;
}
Modified:
root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/richfaces-selection.js
===================================================================
---
root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/richfaces-selection.js 2010-06-30
11:42:30 UTC (rev 17684)
+++
root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/richfaces-selection.js 2010-06-30
15:52:20 UTC (rev 17685)
@@ -9,8 +9,8 @@
} else if (field.createTextRange){
var range = field.createTextRange();
range.collapse(true);
- range.moveEnd('character', pos);
- range.moveStart('character', pos);
+ range.moveEnd('character', end);
+ range.moveStart('character', start);
range.select();
}
}