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

Selected option disappearing on filter #1654

Closed
nkamenar opened this issue Jun 13, 2016 · 4 comments
Closed

Selected option disappearing on filter #1654

nkamenar opened this issue Jun 13, 2016 · 4 comments

Comments

@nkamenar
Copy link

nkamenar commented Jun 13, 2016

Angular: v1.5.0-rc.2

UI-Select: 0.17.1

Bootstrap/Select2/Selectize CSS (if applicable): Bootstrap 3.3.6

UPDATE: I have now been able to reproduce this in a plunker. Everything seems to be working as intended with UI Select 0.16.1 but breaks if you switch to 0.17.1. Here is my plunk, you can swap the commented script lines to see how it works/doesn't work with the two versions:
https://plnkr.co/edit/fduuxU?p=preview

I have been having this problem where when I click to open my select all options show as they should. Then if I type in the options filter as they should but as soon as I delete what I typed so the filter is empty again, instead of all options reappearing in the select dropdown as they should, all options except the currently selected option reappear. I have been unable to reproduce this behavior with a plunker so I am not sure what is going on here.Here is my data and code for reference:

priorityOptions = [
    {"text":"(1) High","value":"(1) High"}, 
    {"text":"(2) Normal","value":"(2) Normal"}, 
    {"text":"(3) Low","value":"(3) Low"} 
  ];

//currentItem is a json object with various data including the PriorityValue field as follows:
currentItem.PriorityValue = "(2) Normal";

Here is my HTML:

<ui-select ng-model="currentItem.PriorityValue" theme="bootstrap" title="Choose a priority">
    <ui-select-match allow-clear="true">{{$select.selected.text}}</ui-select-match>
    <ui-select-choices repeat="option.value as option in (data.priority.options | myfilter: $select.selected: $select.search: 'text')">
        <span ng-bind="option.text"></span>
    </ui-select-choices>
</ui-select>

note: I was originally just using filter: $select.search but when I started experiencing this issue I wrote my own filter to make sure the correct object was being passed back. Here is the code for my custom filter:

myApp.filter('myfilter', function() {
    return function(collection, selected, search, key) {
        var results = [];
        console.log("search: [" + search + "]" );
        if(search == "") {
            for(var obj in collection) {
                results.push(collection[obj]);
            }
            console.log("first results: " +JSON.stringify(results));
            return results;
        }//{ return collection; }
        for(var obj in collection) {
            //console.log(JSON.stringify(collection[obj][key]));
            if (collection[obj][key].toLowerCase().indexOf(search) !== -1) {
                results.push(collection[obj]);
                //delete collection[obj];
            }
        }
        console.log("collection: " + JSON.stringify(collection));
        //console.log(JSON.stringify(selected));
        //console.log(JSON.stringify(search));
        console.log("second results: " +JSON.stringify(results));
        return results;
    }
});

I can verify that when the search box is empty the entire PriorityOptions object listed above is correctly returned from my filter function and so I would expect all options to list, and yet they still do not. The currently selected option always dissapears once you enter some search value and then clear the box.

Also if I include the allow-clear option on the ui-select-match tag above and use it to clear the select then everything works as it should. If I type in the search it filters and if I delete the entered text all options reappear. But, as soon as I select an option it goes back to how it was where the selected option never reappears after you type in the box.

@yaswanth89
Copy link

Observed the same issue v0.18.0 with angular v1.5.7

@LewisCooper4
Copy link

I have also observed this issue v0.17.1 and angular v1.4.7

@user378230
Copy link
Contributor

Note to self: default remove-selected to false for single select mode

@user378230
Copy link
Contributor

This should be resolved by #1690 (v0.18.1) please update this issue with new plunkr if not.

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

No branches or pull requests

4 participants