UISelect multiple , apply CSS to one of the selected items
Asked Answered
M

2

0

Im trying to find ways to apply custom CSS to only one of the selected items in UISelect Multiple.

<ui-select id="productSelect" class="form-control" multiple ng-model="contractsHeader.ProductList" ng-click="addProductOpen()" on-select="onProductSelected($item)" on-remove="onProductRemoved($item)" ng-disabled="!selectedAdvertisers.selectedAdvertiser || !selectedAdvertisers.selectedAdvertiser.AdvertiserKey || selectedAdvertisers.selectedAdvertiser.AdvertiserKey== ' '" ng-required="true" autofocus>
            <ui-select-match>{{getProductDisplayText($item)}}</ui-select-match>
            <ui-select-choices ui-disable-choice="product.Product_Code == null" refresh="searchByTypes('Products',$select.search)" refresh-delay="0" repeat="product in products track by $index | filter:$select.search">
                <div style="cursor:pointer;" ng-if="product.Product_Code == null && securitySettings.addOtherProducts" ng-click="addProductOpen($select, $event)">&lt;{{product.Product_Description}}&gt;</div>
                <div ng-if="product.Product_Code != null">{{product.Product_Description}} ({{product.Product_Code}})</div>
            </ui-select-choices>
        </ui-select>

here is an excerpt of UISelect-Match

<ui-select-match>{{getProductDisplayText($item)}}</ui-select-match>

I tried conditional ng-class to apply CSS to only one element but CSS class is never applied on that item.

Motorbus answered 6/3, 2015 at 13:32 Comment(2)
On which element are you trying to apply the class?Treasonable
Im trying to apply to first element in the selected itemsMotorbus
E
1

This is currently a known issue for ui-select please see: https://github.com/angular-ui/ui-select/issues/277

Essentially, because ui-select has ng-class properties you are unable to effectively apply your custom dynamic classes.

Update 03/08: I resolved my issue (While not pretty) with ng-style, set the css value in your controller(dependent on your condition) attached to a scope variable (as an obj lit), or simply hard code it in the html file within ng-style="" .

Edmanda answered 9/3, 2016 at 21:26 Comment(0)
T
0
<ui-select-match ng-class="(expression) ? 'class1' : 'class2'">
    {{getProductDisplayText($item)}}
</ui-select-match>
Treasonable answered 6/3, 2015 at 14:21 Comment(3)
As i Mentioned i tried ng-class on it and it was not applying that class , i only suspect its because ui-select-match is collection of child elements(li,span...so on)Motorbus
My Bad , no <LI> underneath its collection of DIVs and SpanMotorbus
You could use :first-child on the template html, as I assume you compile the element in the directive?Treasonable

© 2022 - 2024 — McMap. All rights reserved.