indrimuska / angular-selector

A native AngularJS directive that transform a simple <select> box into a full html select with typeahead.
http://indrimuska.github.io/angular-selector
MIT License
96 stars 36 forks source link

scope.filterOptions bug #60

Closed kb0pul closed 8 years ago

kb0pul commented 8 years ago

I noticed that the drop down list always scrolls to the bottom of the drop down list when you open it. I am using single select mode, value-attr and label-attr properties for setup. Upon further investigating I got JS errors popping up after you delete a selection from the list. I traced the issue down to the scope.filterOptions function, and specifically the else block:

scope.filterOptions = function () {
    scope.filteredOptions = filter(scope.options || [], scope.search);
    if (scope.multiple)
        scope.filteredOptions = scope.filteredOptions.filter(function (option) {
            var selectedValues = angular.isArray(scope.selectedValues) ? scope.selectedValues : [scope.selectedValues];
            return !scope.inOptions(selectedValues, option);
         });
    else
         scope.highlight(scope.filteredOptions.indexOf(scope.selectedValues[0]));
};

An if check for scope.selectedValues && scope.selectedValues[0] will eliminate the error, and also fixes the weird issue that the flyout is scrolled to the bottom when opened.

indrimuska commented 8 years ago

Hi @kb0pul, I'm sorry for the late response. I've just verified the bug, let me fix this in a minute. Thank you for reporting this. 👍

indrimuska commented 8 years ago

Check out the new release v1.4.3 with this fix. Thank you again tracing this issue and for reporting it.