Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

[ui.select:choices] Expected multiple .ui-select-choices-row but got '0'. #1355

Closed
ryanwholey opened this issue Dec 11, 2015 · 13 comments
Closed

Comments

@ryanwholey
Copy link

screen shot 2015-12-11 at 12 00 07 pm

Error site found at code below

screen shot 2015-12-11 at 12 02 23 pm

Created a silly workaround for this issue

        setTimeout(function(){
          var container = $element.querySelectorAll('.ui-select-choices');
          for(var i = 0;  i < 2;  i++) {
            var div = document.createElement('div');
            div.className = 'ui-select-choices-row';
            container[0].children[0].appendChild(div);
          }
        });

Thanks!

@lordnox
Copy link

lordnox commented Feb 23, 2016

I had the same error. The bug occured in safari when using the mouse only and I did a little more debugging.

The problem I found was with the ng-if added to the choices itself:
https://github.com/angular-ui/ui-select/blob/master/src/uiSelectChoicesDirective.js#L48

The ng-if seems to trigger after the _ensureHighlightVisible is called, which in turn lets the querySelector not find any elements (ng-if removed them from the DOM). After the error is triggered, the elements will be shown as usual, angular will still trigger the ng-if.
Removing the .attr('ng-if', [...]) removed the bug. I do not know if there are any side effects with this, or if the performance impact is significant enough.

I'd like to have someone else test this, too

@gatormike
Copy link

@lordnox Thanks for the workaround. I have been using Angular 1.5, and recently started getting the same error, as well as strange performance behavior, as if the browser was processing something and scroll was getting reset. I commented out the ng-if (added ; on line before as well).

choices.attr('ng-repeat', $select.parserResult.repeatExpression(groupByExp));
// .attr('ng-if', '$select.open'); //Prevent unnecessary watches when dropdown is close

Performance is back to normal and I do not see this error anymore. Thanks!

edit: I was also using an array of 100+ items, so perhaps an ng-if on each item was causing the lock up.

@Zelgadis87
Copy link

I had the same issue, @gatormike workaround worked for me as a temporary solution.

@ftorghele
Copy link

Me too, removing the .attr('ng-if', [...]) seems to work.

@RenaudRohlinger
Copy link

+1 @gatormike thx.

@jmlora
Copy link

jmlora commented Mar 17, 2016

+1

dondi pushed a commit to dondi/ui-select that referenced this issue Mar 23, 2016
dondi pushed a commit to dondi/ui-select that referenced this issue Mar 23, 2016
...at the cost of potential unnecessary watches when dropdown is closed.
But the premise is that, until the resulting errors are fixed, the
preference is to avoid the errors for now.

Closes angular-ui#1355
dondi added a commit to dondi/ui-select that referenced this issue Mar 23, 2016
...at the cost of potential unnecessary watches when dropdown is closed.
But the premise is that, until the resulting errors are fixed, the
preference is to avoid the errors for now.

Closes angular-ui#1355
@pkuklin
Copy link

pkuklin commented Mar 24, 2016

Hey, guys, I have found how to fix this issue without Forking.
I have added attribute(option) : tagging to the ui-select.
This worked for me, peace!

@wesleycho
Copy link
Contributor

Closing as a duplicate of #224

@devmarwen
Copy link

For my case the source of the bug was this:

      if (ctrl.$animate && ctrl.$animate.on && ctrl.$animate.enabled(container[0])) {
        ctrl.$animate.on('enter', container[0], function (elem, phase) {
          if (phase === 'close') {
            // Only focus input after the animation has finished
            $timeout(function () {
              ctrl.focusSearchInput(initSearchValue);
              console.log('focusSearchInput()'); // Gets called hunreds of times
            });
          }
        });

The ctrl.focusSearchInput(initSearchValue) gets called for too many times which will call the _ensureHighlightVisible(); accordingly.

Removing the ngAnimate module fixes the problem.

@lsanczyk
Copy link

Add the tagging attribute binded to a function that return null, like this plunker, works for me too.

HTML:
<ui-select ... tagging="tagHandler" ... >

JS:

$scope.tagHandler = function (tag){
    return null;
}

@BVJin
Copy link

BVJin commented Oct 11, 2016

@lsanczyk Your solution works for me, thank you!

Angular 1.5.0
ui-select 0.14.3

@deepanshu223
Copy link

Thanks @lsanczyk, your solutions saved my day!

@guoyoujin
Copy link

Thanks @lsanczyk Your solution works for me, thank you! Very good

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.