bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Allow programatically re-opening Typeahead dropdown

Open viveleroi opened this issue 8 years ago • 4 comments

Bug description:

We're trying to re-open the dropdown on input focus but there are only two paths that might have worked: typeahead-is-open and assignIsOpen({ isOpen: true }).

Neither works because uib internally checks scope.choices.length right after resetting the matches array, meaning the isOpen method always returns false.

Fixing this could also allow a user-controlled solution to #6046.

Link to minimally-working plunker that reproduces the issue:

http://plnkr.co/edit/XRjoYZO0BZuOWXaMlGgy?p=preview

Version of Angular, UIBS, and Bootstrap

Angular 1.5.8, uib 2.0.2, bootstrap 3.x

viveleroi avatar Sep 13 '16 22:09 viveleroi

I would like to open the typead if there is already an option selected

gino8080 avatar Nov 29 '16 19:11 gino8080

Possible solution -> create own directive like so;

app.directive('typeaheadAsSelect', [function() {
    return {
        restrict: 'A',
        require: ['ngModel'],
        link: function($scope, $element, attrs, ctrls){
            $element.bind('focus', function(){
                $scope.prevValue = ctrls[0].$viewValue;
                ctrls[0].$setViewValue("");
            });
            $element.bind('blur', function(){
                setTimeout(function(){
                    if(!ctrls[0].$viewValue && $scope.prevValue) {
                        ctrls[0].$setViewValue($scope.prevValue);
                        ctrls[0].$render();
                    }
                }, 150);
            });
        }
    }
}]);

Usage:

<input uib-typeahead="..." typeahead-as-select />

Klinton90 avatar Feb 16 '17 20:02 Klinton90

Found similar issue on this stackoverflow thread. The solution that is working for me is simply adding typeahead-min-length attribute like so: <input type="text" typeahead-min-length="0" uib-typeahead="t for t in timeZoneList">

1993Dajana avatar Apr 08 '17 04:04 1993Dajana

The solution referenced by 1993Dajana does not address this problem (opening the dropdown when input receives focus even after it contains a value.). The provided plunker already sets typeahead-min-length="0".

r20 avatar Nov 15 '17 16:11 r20