Harvest-Dev / ng-select2

A select2 for Angular
MIT License
55 stars 32 forks source link

Form Reset Not Triggering Events #69

Closed tibinvpaul closed 2 months ago

tibinvpaul commented 3 months ago

I am using the select2 component with a reactive form. I have a reset button that resets the form on click. However, events like update are not triggering on reset. Additionally, I am using hideSelectedItems to hide the selected item. After the reset, the list items remain in the previous state. The expectation is that the list items will include all items, as the selected value is empty after a reset.

I have set up a Stackblitz here to reproduce the issue. Could you please take a look and let me know if I am doing something wrong or if this needs to be fixed in the package itself?

Steps to Reproduce

  1. Add 2 items to the component.
  2. Click on Reset.
  3. Click on the component. The list items are empty.
  4. Also, the update event is not triggering on reset.

Thank you!

tibinvpaul commented 3 months ago

Hi @Zefling - Thank you very much for V15.0.1, which addresses the issue. Our Angular applications have not yet been upgraded to V18, so we are still using V13 of the select2 component. Is it possible to release a patch for V13 with this fix, if it is not too difficult? Thank you.

Zefling commented 3 months ago

https://www.npmjs.com/package/ng-select2-component/v/13.0.12

tibinvpaul commented 3 months ago

Thanks a lot, @Zefling. I will test it out and update the thread!!!

tibinvpaul commented 3 months ago

Hi @Zefling

Has anything else changed in 13.0.12? The use case below was working in 13.0.4 but not in 13.0.12. I've observed the same issue in version 15 as well. Here are the component options:

customSearchEnabled = true

When the (search) event is triggered, I am making an API call to update the list. However, the already selected items disappear if they are not available in the updated list.

  1. Search for Earth.
  2. Select it.
  3. Search for Mars.
  4. Server returns the results for Mars.
  5. This list does not include Earth.
  6. The already selected Earth is no longer available.
  7. Search again for Earth. Now, Earth will reappear in the selection. This is because the list now has Earth.

I think this must work correctly when hideSelectedItems=true too.

Zefling commented 3 months ago

Ok, this is a another bug. Please, open a new issue.