Skip to content

Commit

Permalink
the current implementation of autocomplete does not currently handle …
Browse files Browse the repository at this point in the history
…a few cases:

- predefined values
- using the typeInvite
- in some cases, it looses its value
- in some cases it sends an autocomplete command when it should not.

Some of these issues have to do with balancing the hidden from the actual element.  This patch fixes this issue.
  • Loading branch information
adam brin authored and ericabouaf committed Feb 14, 2010
1 parent 967416c commit 9348965
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions js/fields/AutoComplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
inputEx.AutoComplete = function(options) {
inputEx.AutoComplete.superclass.constructor.call(this, options);

};

lang.extend(inputEx.AutoComplete, inputEx.StringField, {
Expand All @@ -26,7 +27,7 @@ lang.extend(inputEx.AutoComplete, inputEx.StringField, {
*/
setOptions: function(options) {
inputEx.AutoComplete.superclass.setOptions.call(this, options);

// Overwrite options
this.options.className = options.className ? options.className : 'inputEx-Field inputEx-AutoComplete';

Expand All @@ -49,7 +50,8 @@ lang.extend(inputEx.AutoComplete, inputEx.StringField, {
inputEx.AutoComplete.superclass.initEvents.call(this);

// remove standard blur listener
Event.removeBlurListener(this.el, this.onBlur);
// Event.removeBlurListener(this.el, this.onBlur);
// Event.removeFocusListener(this.el, this.onFocus);
},

/**
Expand All @@ -68,7 +70,7 @@ lang.extend(inputEx.AutoComplete, inputEx.StringField, {
if(this.options.size) attributes.size = this.options.size;
if(this.options.readonly) attributes.readonly = 'readonly';
if(this.options.maxLength) attributes.maxLength = this.options.maxLength;

// Create the node
this.el = inputEx.cn('input', attributes);

Expand Down Expand Up @@ -135,14 +137,23 @@ lang.extend(inputEx.AutoComplete, inputEx.StringField, {
var aData = aArgs[2];
this.setValue( this.options.returnValue ? this.options.returnValue(aData) : aData[0] );
},


onBlur: function(e){
YAHOO.log("onBlur h:"+ this.hiddenEl.value + "| v:"+this.el.value + " inv:" + this.options.typeInvite + " " + this.isEmpty());
if (this.hiddenEl.value != this.el.value && this.el.value != this.options.typeInvite) this.el.value = this.hiddenEl.value;
if(this.el.value == '' && this.options.typeInvite) {
Dom.addClass(this.divEl, "inputEx-typeInvite");
if (this.el.value == '') this.el.value = this.options.typeInvite;
}
},
/**
* onChange event handler
* @param {Event} e The original 'change' event
*/
onChange: function(e) {
this.setClassFromState();
// Clear the field when no value
if (this.hiddenEl.value != this.el.value) this.hiddenEl.value = this.el.value;
lang.later(50, this, function() {
if(this.el.value == "") {
this.setValue("");
Expand All @@ -156,9 +167,8 @@ lang.extend(inputEx.AutoComplete, inputEx.StringField, {
* @param {boolean} [sendUpdatedEvt] (optional) Wether this setValue should fire the updatedEvt or not (default is true, pass false to NOT send the event)
*/
setValue: function(value, sendUpdatedEvt) {

this.hiddenEl.value = value || "";

this.el.value = value || "";
// "inherited" from inputex.Field :
// (can't inherit of inputex.StringField because would set this.el.value...)
//
Expand Down

0 comments on commit 9348965

Please sign in to comment.