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 ngModel must be `undefined` for min-length="0" to work #6283

Open matthias-ccri opened 7 years ago

matthias-ccri commented 7 years ago

Bug description:

What should happen: When the attribute typeahead-min-length="0" is present, focusing on the field should trigger the results dropdown to display. This works only when the ngModel is set to undefined, but it does not work when it is set to null.

Plunkr:

https://plnkr.co/edit/dqqcVIGFcVFzvqn2fu4t?p=preview This is the stock typeahead Plunkr, with only one line changed in example.js: $scope.customSelected = null;

Versions

Angular: 1.5.8 UIBS: 2.2.0 Bootstrap: 3.3.7

wesleycho commented 7 years ago

This would be a breaking change - I'm not necessarily against this, but this could have unintended consequences.

shyamal890 commented 7 years ago

I added a directive to solve the issue temporarily. It simply triggers input change on focus. However typeahead-min-length="0" implicitly means that typeahead should trigger on focus. Hope Angular-UI team solves this eventually.

app.directive('typeaheadShowOnFocus', function () {
    return {
        require: 'ngModel',
        link: function ($scope, element, attrs, ngModel) {
            element.bind('focus', function () {
                ngModel.$setViewValue();
                $(element).trigger('input');
                $(element).trigger('change');
            });
        }
    };
});

Plunker Example : https://plnkr.co/edit/ifaZMhsFaHrQZFOaIA0w?p=preview

InFerYes commented 7 years ago

I'm experiencing the same issue, that the dropdown doesn't show after clearing the ng-model in code. As soon as I enter anything (and clear via keyboard), the dropdown works again.

The above directive doesn't work for me.

Making sure the value binded to the ng-model is not null is a workaround.