Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single select selection will not unselect multiselects #11

Open
TomasKatz opened this issue Sep 26, 2019 · 3 comments
Open

Single select selection will not unselect multiselects #11

TomasKatz opened this issue Sep 26, 2019 · 3 comments

Comments

@TomasKatz
Copy link

Tag configuratuion:

<mat-select-autocomplete 
[options]="allEvents" 
[multiple]="true" 
[value]="'id'" 
[display]="'name'" 
name='parentEvent' 
ngDefaultControl
formControlName="parentEvent">
</mat-select-autocomplete>	

options Object:

[
    {
       name:'a',
       id:1
    },
    {
       name:'b',
       id:2
     },
    {
       name:'c',
       id:3
     }
    //... about 200 more items
]

Way to reproduce:
Select an the "all options checkbox" -> see that all options were selected -> click again on the "select all/ unselect all" checkbox -> result: selected options do not get unselected, they stay selected.

@HansWouters
Copy link

HansWouters commented Nov 29, 2019

I probably have a clue why the issue occurs:
When unselecting, this code runs:

  const filteredValues = this.getFilteredOptionsValues();
  this.selectedValue = this.selectedValue.filter(item => !filteredValues.includes(item));
...
    getFilteredOptionsValues() {
        /** @type {?} */
        const filteredValues = [];
        this.filteredOptions.forEach(option => {
            filteredValues.push(option.value);
        });
        return filteredValues;
    }

So for getFilteredOptionsValues to return correct values, the option must have its value filled. You probably want something like
option => {filteredValues.push(option[this.value]);});
but it seems like you cannot reach that because of the inner function.

Not sure how to best fix this though, I've not looked into the code deep enough.

@martinoliete
Copy link

I have the same problem, Can you resolve this?

@Moazmostafaa
Copy link

I had the same problem, Try to map your options list like that :

this.filteredGovItems = this.allGovs.map(x => {
return {
display: x.name,
value: x.id
};
});

it will work correctly.

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

No branches or pull requests

4 participants