angular-ui / bootstrap

PLEASE READ THE PROJECT STATUS BELOW. Native AngularJS (Angular) directives for Bootstrap. Smaller footprint (20kB gzipped), no 3rd party JS dependencies (jQuery, bootstrap JS) required. Please read the README.md file before submitting an issue!
http://angular-ui.github.io/bootstrap/
MIT License
14.29k stars 6.73k forks source link

Typeahead throws exception on exact match #6472

Open Klinton90 opened 7 years ago

Klinton90 commented 7 years ago

Bug description:

When using typeahead with attributes typeahead-select-on-exact="true" and typeahead-show-hint="true" exception is thrown when exact match happens: Cannot read property 'label' of undefined

Link to minimally-working plunker that reproduces the issue:

https://plnkr.co/edit/HrKQIcOy0XjN9BBosdRS?p=preview

Steps to reproduce the issue:

1) Open DevTools 2) Type "Alabama" in input field 3) Error appears in log.

jesusmogollon commented 7 years ago

Same problem here...

I'm looking for a work around in the meanwhile.

jesusmogollon commented 7 years ago

I have changed the getMatchesAsync function, that was the easiest way that I have found to make it work.

          if (showHint) {
                if (scope.matches.length > 0)
                {
                  var firstLabel = scope.matches[0].label;
                  if (angular.isString(inputValue) &&
                    inputValue.length > 0 &&
                    firstLabel.slice(0, inputValue.length).toUpperCase() === inputValue.toUpperCase()) {
                    hintInputElem.val(inputValue + firstLabel.slice(inputValue.length));
                  } else {
                    hintInputElem.val('');
                  }
                }
            }