bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Bug: Typeahead broken in latest angular

Open noducks opened this issue 12 years ago • 19 comments

Seems Typeahead isn't working correctly since v1.3.0-build.2783.

Keyboard jumps through the items, but it doesn't highlight them, so you can't see which one is selected. Clicking with the mouse on the typeahead list doesn't update the input.

These bugs show up in Chrome and Safari, haven't tried any other browsers.

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

noducks avatar Jun 03 '14 22:06 noducks

Indeed, this sounds like a regression on the AngularJS side.... Not sure what could have caused this atm, though.

pkozlowski-opensource avatar Jun 04 '14 06:06 pkozlowski-opensource

I'm not seeing the popup's methods being called

caitp avatar Jun 04 '14 11:06 caitp

Just ran into this too

myitcv avatar Jun 10 '14 13:06 myitcv

+1 it was working fine till 1.3.0-beta.5.

xmlking avatar Jun 14 '14 23:06 xmlking

Looks like this actually broke in v1.3.0-beta.11. It appears to be working in v1.3.0-beta.10

myitcv avatar Jun 17 '14 10:06 myitcv

@caitp just looking into this, but I'm not 100% sure which exact commit broke this :-/

pkozlowski-opensource avatar Jun 17 '14 17:06 pkozlowski-opensource

It's likely related to Pete/Vojta's transclusion fixes, @pkozlowski-opensource --- but I think we don't want to revert those changes

caitp avatar Jun 18 '14 01:06 caitp

@caitp - presumably those fixes relate AngularJS 5489 amongst others?

On the basis any changes like this to transclusion are likely to have wider reaching impact, is there a document somewhere that captures the scope and impact of said changes? I suspect typeahead won't be the only place affected.

myitcv avatar Jun 18 '14 05:06 myitcv

Any simple workaround other than dropping back to an older version of angular?

davisford avatar Jul 10 '14 02:07 davisford

AngularJS #8072 appears to confirm the bug is within angular-ui. However I can't make the solution proposed by @wazzeb work against AngularJS master.

myitcv avatar Jul 10 '14 16:07 myitcv

setting typeahead-template-url also appears to be broken in Angular 1.3.0-beta14.

joshbowdoin avatar Jul 11 '14 00:07 joshbowdoin

I've submitted #2535 as a fix for this. I've confirmed that this does fix the issue with 1.3.0-beta.17. Simple change, but it works just fine.

nivthefox avatar Aug 01 '14 08:08 nivthefox

@kkragenbrink Just tried that out. Works great on Chrome, Safari, IOS & Android.

Who would have thought it'd be that simple! Thanks.

noducks avatar Aug 01 '14 16:08 noducks

+1

futurechan avatar Aug 14 '14 20:08 futurechan

Use decorator to extend third party directives, so that if they are upgrading you can upgrade your lib without code change, just you can remove your decorator. <!DOCTYPE html> <html>

<head> <title>Adding/modifying predefined Services/Direcives</title> <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.12.1/ui-bootstrap-tpls.js"></script> <link rel="stylesheet" type="text/css" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"> <script> '''javascript window.onload = function() { //After loading scripts

    var decoApp = angular.module('decoApp', ['ui.bootstrap']);
    decoApp.run(['$rootScope',
        function(r) {
            r.states = [];
            for (var a = 1000; a > 0; a--) {
                r.states.push({
                    name: "state" + a,
                    id: a
                });
            }
        }
    ]);
    decoApp.config(function($provide) {
        $provide.decorator('typeaheadDirective', function($delegate) {
            //console.log($delegate);
            var directive = $delegate[0];
            var link = directive.link;
            var keyCodes = {
                37: 'left',
                39: 'right',
                38: 'up',
                40: 'down'
            };
            directive.compile = function() {
                console.log('compiling');
                return function(scope, element, attrs) {
                    console.log(element, attrs);

                    link.apply(this, arguments);
                    setTimeout(function() { //time delay to render the directive by angular
                        var dropdownId = element[0].attributes.getNamedItem('aria-owns').value;
                        var dropdownElement = angular.element(document.getElementById(dropdownId));
                        dropdownElement.css('height', '200px');
                        dropdownElement.css('overflow-y', 'scroll');
                        //bind event
                        element.on('keydown', function(e) {
                            if (!!keyCodes[event.keyCode]) {
                                if (e.target.attributes.getNamedItem('aria-owns').value === dropdownId) {
                                    var activeItemId = e.target.attributes.getNamedItem('aria-activedescendant').value;
                                    var top = document.getElementById(activeItemId).offsetTop;
                                    dropdownElement[0].scrollTop = top;
                                }
                            }
                        });
                        //unbind event
                        var destroyEvent = scope.$on('$destroy', function() {
                            console.log('$destroy');
                            if (typeof destroyEvent === 'function') {
                                destroyEvent();
                            }
                            element.off('keydown');
                        });
                    }, 2000);
                };
            };
            return $delegate;
        });
    });
    angular.bootstrap(document, ['decoApp']);
}

''' </script> </head>

<body> <div class="form-group"> <label>Type a number</label> <input class="form-control" type="text" ng-model="selected" typeahead="state.name for state in $root.states | filter:$viewValue | limitTo:28" class="form-control"> </div> </body> </html>

9442552055 avatar Mar 04 '15 09:03 9442552055

I'm still having the same type-ahead problems with 1.4.5. Has this problem now been confirmed solved?

jonathanmclarke-zz avatar Sep 05 '15 11:09 jonathanmclarke-zz

I am also facing the same problem. Using Bootstrap 0.11.0 and angular js 1.4.8.

ashigl avatar Jan 15 '16 23:01 ashigl

@ashigl, please do not comment on closed issues. doing so is a really good way for them to be missed or ignored.

icfantv avatar Jan 15 '16 23:01 icfantv

I am also facing the same problem. Using Bootstrap v3.3.6 and angular js v1.4.7

cscuser avatar Jul 27 '17 10:07 cscuser