ui-select icon indicating copy to clipboard operation
ui-select copied to clipboard

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

Open ryanwholey opened this issue 10 years ago • 13 comments

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!

ryanwholey avatar Dec 11 '15 20:12 ryanwholey

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

lordnox avatar Feb 23 '16 11:02 lordnox

@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.

gatormike avatar Feb 23 '16 20:02 gatormike

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

Gabriele-Tomberli avatar Feb 25 '16 22:02 Gabriele-Tomberli

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

ftorghele avatar Mar 04 '16 06:03 ftorghele

+1 @gatormike thx.

RenaudRohlinger avatar Mar 16 '16 09:03 RenaudRohlinger

+1

jmlora avatar Mar 17 '16 15:03 jmlora

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!

pkuklin avatar Mar 24 '16 09:03 pkuklin

Closing as a duplicate of #224

wesleycho avatar Mar 28 '16 05:03 wesleycho

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.

devmarwen avatar Apr 16 '16 10:04 devmarwen

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;
}

lsanczyk avatar Apr 21 '16 18:04 lsanczyk

@lsanczyk Your solution works for me, thank you!

Angular 1.5.0 ui-select 0.14.3

BVJin avatar Oct 11 '16 21:10 BVJin

Thanks @lsanczyk, your solutions saved my day!

deepanshu223 avatar Nov 24 '16 16:11 deepanshu223

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

guoyoujin avatar Mar 10 '17 01:03 guoyoujin