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

When ui-select is inside a modal popup, items do not show up properly

Open pierznj opened this issue 11 years ago • 15 comments

I'm experiencing the same problem as described here: http://stackoverflow.com/questions/29893423/angular-ui-select-is-not-displaying-the-list-of-options-when-included-in-angular The second answer to that issue appears to be correct. For some reason, the $select.items.length is 0, causing the dropdown list to be ng-hidden, even though the items are there (and can be seen if you inspect the DOM). Only solution appears to be hacking the template, as is suggested in the above SO post.

pierznj avatar Aug 06 '15 03:08 pierznj

I just ran into this while trying to use ngDialog. I noticed the ng-hide on the select options too, so I hacked it and added ng-hide="!$select.open" to my select-choices effectively overriding the logic within which allowed me to get it working without messing with the template. Hope this helps others :)

DeezCashews avatar Aug 07 '15 21:08 DeezCashews

I got this to work by altering the template in a hacky way. You can see below that I switched from using ng-show to a bound expression in the style attribute.

style="display:{{$select.items.length && $select.open ? \'block\':\'none\'}}"

Earlier, I had tried ng-hide, ng-show, and ng-class, and none of them worked. I wonder if this has to do with some kind of ng-animate behavior?

Full copy/paste available below: (adjust the theme prefix as necessary)

.run(function ($templateCache) {
  $templateCache.put('bootstrap/choices.tpl.html',
      '<ul class="ui-select-choices ui-select-choices-content dropdown-menu" role="listbox" style="display:{{$select.items.length && $select.open ? \'block\':\'none\'}}" >' +
          '<li class="ui-select-choices-group" id="ui-select-choices-{{ $select.generatedId }}">' +
            '<div class="divider" ng-show="$select.isGrouped && $index > 0"></div>' +
            '<div ng-show="$select.isGrouped" class="ui-select-choices-group-label dropdown-header" ng-bind="$group.name"></div>' +
            '<div id="ui-select-choices-row-{{ $select.generatedId }}-{{$index}}" class="ui-select-choices-row" ' +
              'ng-class="{active: $select.isActive(this), disabled: $select.isDisabled(this)}" role="option">' +
                '<a href="javascript:void(0)" class="ui-select-choices-row-inner"></a>' +
            '</div>' +
          '</li>' +
      '</ul>');
});

noblebright avatar Aug 12 '15 01:08 noblebright

Error occurs here in select.js

(line 610: ctrl.searchInput.css('width', '10px');)

In this case input tag has width: 10px. You can click in this 10px-area - and it will work. As we use this lib via bower - I've fix it without touching source in the following way:

<ui-select-match placeholder="placeholder..." ng-class="{empty: !account.roles.length}">{{::$item.name}}</ui-select-match>

so, if model array is empty - just make width of input 100%. We use 'select2' theme

.empty.ui-select-match + .select2-search-field,
.empty.ui-select-match + .select2-search-field input{
    width: 100% !important;
}

captify-ddavydov avatar Aug 14 '15 11:08 captify-ddavydov

@DeezCashews thanks a lot. It works well in my case.

maxwls avatar Oct 09 '15 09:10 maxwls

@curios no problem, if you want to upvote my answer on the SO link mentioned it will help others find faster

DeezCashews avatar Oct 09 '15 13:10 DeezCashews

I've experienced this issue when I've nested my ui-select inside an ng-show initially set to be false when the page is first rendered. I've tracked it down to the ctrl.sizeSearchInput function inside the uiSelectCtrl controller, the search input is set to 10px wide and this doesn't change after the ng-show section is visible.

I've followed the advice of @captify-ddavydov for now and implemented styles that don't include the .empty class name (as my situation isn't about an empty list - my list is populated at the point the problem happens).

.ui-select-match + .select2-search-field,
.ui-select-match + .select2-search-field input{
    width: 100% !important;
}

andrewmurray avatar Dec 16 '15 14:12 andrewmurray

Scrap the above, that breaks the rendering - it causes the control to render two lines when an option is selected:

2015-12-16_14h40_43

andrewmurray avatar Dec 16 '15 14:12 andrewmurray

Try using ng-if instead of ng-show. It solved for me.

prakhar-goel avatar Jan 23 '16 09:01 prakhar-goel

Using ng-if instead of ng-show also solved it for me.

CodeStrumpet avatar Jan 23 '16 19:01 CodeStrumpet

Experienced this same issue when ui-select was in a collapsing panel hidden with ng-class. I ended up using the same fix as @captify-ddavydov and @andrewmurray. I can live with the doubled height that @andrewmurray mentions.

For anyone using the Boostrap theme, this is all it took for me:

ui-select-match + .ui-select-search,
.ui-select-match + .ui-select-search input{
    width: 100% !important;
}

jcluts avatar Jan 23 '16 20:01 jcluts

Closing this as a usage issue.

wesleycho avatar Mar 27 '16 23:03 wesleycho

@prakhar-goel Where does the ng-if go?

voltechs avatar Jul 15 '16 19:07 voltechs

I'm bitten by this issue. Tried many of the solutions and none work. The issue happens inside an ng-show which is exposing the select list when a button is clicked. If I move the select outside of the show it works. Boo.

tkserver avatar Apr 21 '17 21:04 tkserver

@tkserver

I also met this problem while using ui-modal and I solve this using 'ng-class' condition to the ui-select-choices directive:

modal.html

<ui-select ng-model="person.selected" theme="bootstrap" on-select="onSelect($item)" ng-click="select_open = true">
    <ui-select-match placeholder="制作者">{{$select.selected.name}}</ui-select-match>
    <ui-select-choices repeat="item in people | propsFilter: {name: $select.search, email: $select.search}" ng-class="{ 'select_open': select_open }">
        <div ng-bind-html="item.name | highlight: $select.search"></div>
        <small ng-bind-html="item.email | highlight: $select.search"></small>
    </ui-select-choices>
    <ui-select-no-choice>
        一致するものは見つかりませんでした。
    </ui-select-no-choice>
</ui-select>

app.js

$scope.onSelect = function(item) {
    $scope.open_select = false;
	}

style.css

.select_open {
	opacity: 1 !important;
}

Hope it helps. 👍

ghost avatar Mar 09 '18 03:03 ghost

Thanks for the tip! I'm trying to remember what I was doing and what project I was on so I can use it!

tkserver avatar Mar 09 '18 04:03 tkserver