2

I'm using the following piece of code to select item if it is present in filters

            <div ng-repeat="category in categories.data" ng-model="div1">
            <div ng-repeat="(key, value) in category" mg-model="div1.div2">
                {{ key + ":"}}
                <select id={{key}} class="my_select"
                        data-ng-model="CategoryOption"
                        data-ng-change="updateCategories()"
                        data-ui-select2="{}" multiple >
                    <option ng-repeat="c in value"
                            ng-selected="(filters[key].length>0) && (filters[key].indexOf(c.trim()) !== -1)" >
                        {{c.trim()}}</option>
                </select>

            </div>
        </div>

But it actually doesn't select anything... Other option is to set ng-model to filters.key, but selecting one element will cancel out the selection in another select, because they are bind to the same model...

Given my setup from above, how can I restore my selection, using select2 multiple ?

1 Answer 1

0

The only solution I found for my problem was to modify select2.js once again.

I used to pass a custom argument:

<select id={{key}} class="my_select"
                   ng-model="select2"
                   ui-select2="{mySelection: filters[key] }" multiple >
                   <option ng-repeat="c in value track by $index"
                       value="{{c.trim()}}">{{c.trim()}}</option>
</select>

and in select2 I applied following changes:

if(opts.mySelection && typeof opts.mySelection != undefined) {
    elm.val(opts.mySelection).trigger("change");
}

just before:

controller.$render();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.