#116 new
robechar

Ajax.Autocompleter default selects first item

Reported by robechar | November 8th, 2008 @ 01:19 AM

The default action for the autocompleter is to select the first item in the list it returns. This causes problems if the first item is not what you want.

I think the correct action should be the way that Google suggest works, by not initially selecting an item until the user clicks it, or presses the down arrow. At least auto selecting the first item should be able to be disabled.

control.js line 131

remove:

this.selectEntry();

replace with:

if (this.index > -1){

   this.selectEntry();

}

Also control.js line 313

remove:

this.index = 0;

replace with:

this.index = -1;

Comments and changes to this ticket

  • Taco

    Taco August 4th, 2009 @ 11:48 AM

    I had the same problem, but the solution I found is slightly more complicated. It uses this.oldElementValue to retreive the typed text, so your input doesn't go to waste when you browse the suggestions.

    markPrevious: function() {

    if(this.index > -1) this.index--;
      else this.index = this.entryCount-1;
    if(this.index > -1 ) {
      this.getEntry(this.index).scrollIntoView(true);
      this.updateElement(this.getCurrentEntry());
    }
    else {
      this.element.value = this.oldElementValue;
    }
    

    },

    markNext: function() {

    if(this.index < this.entryCount-1) this.index++;
      else this.index = -1;
    if(this.index > -1 ) {
      this.getEntry(this.index).scrollIntoView(false);
      this.updateElement(this.getCurrentEntry());
    }
    else {
      this.element.value = this.oldElementValue;
    }
    

    },

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

script.aculo.us is an open-source JavaScript framework for visual effects and interface behaviours.
<br/><b>Source available from github</b>
The Git repository resides at:
<a href="http://github.com/madrobby/scriptaculous">http://github.com/madrobby/scriptaculous</a>
<br/>Check out the current development trunk with:
<code>git clone git://github.com/madrobby/scriptaculous.git</code>
<br/>As <b>script.aculo.us 1.xx is feature-frozen</b>, this development trunk is for <b>bugfixes only</b>.
<br/>New development should happen only for
<b>script.aculo.us 2</b>.
<br/><b>Creating a bug report</b>
When creating a bug report, be sure to include as much relevant information as possible. Post a an example that shows off the problem. Preferably, <b>alter the unit tests</b> and show through either changed or added tests how the expected behavior is not occuring.

People watching this ticket

Pages