-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Autocomplete onSelectionChange fires two times when changing previously selected value #4094
Comments
👍 |
👍 to this, having the same problem, what makes it worst is onSelectionChange emits |
The problem here is that the "onSelectionChange" is an event from the md-option component. What is really happening is that, when you select a new option on the md-autocomplete, it select the new option and then "deselect" the old one. You get the first event with the new option and the second event with the old option. If you look at this Plunker (Open the console and change the options), you'll see that the first event will have an I've already created the issue #3645 to create an event for the md-autocomplete selectionChange, so we'll not need to rely on the md-options events. For now, you can "fix" your problem by checking the |
Emits the `select` event when an option in the autocomplete is selected. **Note:** I went with passing the selected option from the trigger to the panel, instead of listening to the `onSelectionChange` inside the panel, because it involves keeping track of less subscriptions and not having to re-construct them when the list of options changes. Fixes angular#4094. Fixes angular#3645.
Thanks @jefersonestevo - was having the same issue and resolved it with your fix. Looking forward for the MD guys to release the much awaited "onOptionSelected" and "onBlurWithNoSelection" events! |
Any ETA when this would be released? |
Any ETA if / when this would be planned? |
Any word on this update? |
Emits the `select` event when an option in the autocomplete is selected. **Note:** I went with passing the selected option from the trigger to the panel, instead of listening to the `onSelectionChange` inside the panel, because it involves keeping track of less subscriptions and not having to re-construct them when the list of options changes. Fixes angular#4094. Fixes angular#3645.
Emits the `select` event when an option in the autocomplete is selected. **Note:** I went with passing the selected option from the trigger to the panel, instead of listening to the `onSelectionChange` inside the panel, because it involves keeping track of less subscriptions and not having to re-construct them when the list of options changes. Fixes angular#4094. Fixes angular#3645.
After updating to the latest release, I'm still getting 2 events fired. As explained in the previous comments, one seems to be the "selected" option and one seems to be the "deselected" option. Is this something that will not be fixed/changed? In case others ran into the same problem, the workaround I used was checking the "isUserInput" attribute on the event which will only be "true" for the selected option event, but false for the "deselected" option. |
That's because the same event fires for selecting and deselecting an option. If you want an event that only fires when an option is selected, you can subscribe to the |
Ah I see, thank you! |
Hi I try to use it also but nothing happen when I write it on the Example works with beta.10 :
Example didn't work with beta.11 :
Example works with beta.11 :
How to put it on the |
The onSelectionChange will fire two events one with isUserInput true and one with false. And in component:
|
see also this issue. I would like if this was fixed as it seems everyone tries to do it one way, only to find out that they have to use events instead. Sort of negates the point of 'onSelectedChanged' if 'optionSelected' is the only way to go. |
@Swoox Gracias tu solución me sirvió mucho. Saludos!! |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug:
If the autocomplete input field already has a value and this is changed by deleting the previous value and selecting a new option from the list, then the autocomplete's
onSelectionChange
fires twice.What is the expected behavior?
When editing/ changing the previous selected value
onSelectionChange
should fire only once.What is the current behavior?
When editing/ changing the previous selected value
onSelectionChange
fires twiceWhat are the steps to reproduce?
Step 1: Select a value from autocomplete dropdown
Step 2: Clear this value (use backspace/ select all and erase)
Step 3: Select a different value from the autocomplete
Providing a Plunker (or similar) is the best way to get the team to see your issue.
https://plnkr.co/edit/cOYg48HGf86ZtG0fO59r?p=preview
What is the use-case or motivation for changing an existing behavior?
When you want to edit a pre-filled value or you selected a value by mistake and want to make a change and if there are other fields dependent on this value, then the dependent values don't get updated.
Which versions of Angular, Material, OS, browsers are affected?
"@angular/material": "^2.0.0-beta.3"
OS: Mac
browser: Chrome/ Safari
Is there anything else we should know?
Nope.
The text was updated successfully, but these errors were encountered: