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
Introduce clear event, and clear values before unselect event is triggered #5058
Conversation
f36115e
to
49c8322
Compare
This looks good, and I appreciate that you added some tests as well! Could you add a few comments to explain what your changes in |
Sure. If you need some comments in code, I can add them as well. The ProblemLet's say you have a single select with The Fix, part 1I've described that issue in #5049. This PR fixes it. The value before clearing is stored in a temporary variable and actual value is cleared. Then The Fix, part 2In addition, I've added another event,
|
Ok, I think I'm starting to understand. Basically, this makes the behavior of "clear selection in single-select" and "remove selection in multi-select" consistent. In that with your patch, in both cases the actual value of the control (as accessed via The data passed to these events though, is the same, right? It's the entire data properties object of the selection that was cleared/unselected? |
Also, what happens with |
Exactly, To be honest, I haven't tested |
Cool! I only ask because I know that there are some issues about Can you test this? This might be a good opportunity to deal with all of these |
For the issue with #3772. I've applied the new code changes of @gronostajo, but it does not work as expected. When you press backspace in multi selection, all selected items will be removed. |
@hoanghuan0701 thanks! But from what I can tell of #3772, this was a problem even without @gronostajo's patch? Can you confirm whether this patch is actually introducing a new bug? |
@alexweissman It seems that #3773 is resolved. #3772 is present in my gist which demonstrates the problem I attempted to fix. Just add |
That's fine, I just want to make sure that we're not introducing any new bugs. |
Merged into |
This pull request includes a
The following changes were made
unselect
event is emitted (fixes select2:unselect fires before changing value in single-select dropdowns #5049). If the event is cancelled, the original value will be restored.clear
event was added which is emitted only when clearing and unlikeunselect
, it's always emitted only once for multiple select (instead of once for each cleared item). This event is also cancellable, and if so, nounselect
events are emitted. (closes Event on clear #4929 and probably AllowClear event #5045)