Skip to content

Need to add a break; in the _typeahead method #337

@deansimcox

Description

@deansimcox

Hi

I discovered a bug in the _typeahead method. If a list has multiple entries that start with the same letters, for example 'al', it will go to the last option starting with 'al'.

It's because of this part:

if ( thisText === matchee ) {
    if ( self._typeAhead_cycling ) {
        if ( nextIndex === null )
            nextIndex = i;
        if ( i > selectedIndex ) {
            nextIndex = i;
            break;
        }
    } else {
        nextIndex = i;
    }
}

Becuase there is no 'break;' in the else part of that statement, is doesn't get out of the for loop.

So change it to this:

if ( thisText === matchee ) {
    if ( self._typeAhead_cycling ) {
        if ( nextIndex === null )
            nextIndex = i;
        if ( i > selectedIndex ) {
            nextIndex = i;
            break;
        }
    } else {
        nextIndex = i;
        break;
    }
}

Add fixed. The first option that matches will be selected.

Cheers :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions