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

[Bug]: Removing items removes all duplicates in a specific scenario. #762

Open
StephenLongville opened this issue Aug 22, 2024 · 1 comment
Labels
bug Something isn't working stale No activity

Comments

@StephenLongville
Copy link

StephenLongville commented Aug 22, 2024

Bug description

removeItem() does a check to remove the option too - if (!self.settings.persist && self.userOptions.hasOwnProperty(value))

However it doesn't take into account a very specific programmatic setup - adding items to options and selections as user created, but not persisting when removed, also allowing duplicates (see Additional context).

In this scenario, I add additional items that are not part of the "normal allowed selection" programmatically, but when removing these additional values, it removes all duplicates, not just the clicked item because of a recursive loop of removeItem() -> removeOption() -> removeItem()...

Expected behavior

Regardless of if an item is user created or not, removing it should remove just that single item and no other items. If the item removed was a duplicate, it's option should stay present as it's still present as a selected item.

Steps to reproduce

JS Fiddle: https://jsfiddle.net/stigmund/wg8po1yt/19/

  1. Remove either of the great tags.
  2. Both tags and the option are removed.

Additional context

I realize I'm adding the option as "created" manually, and then turning off the create option, and this is the root cause of my issue, however there is a valid reason for this.

I am loading content into multiple fields, generated by user maintained formula (producing delimited strings). It is important for us to show all values the user configured in the formulas - valid or not - and alert the user on form submission of the "bad values".

I also need to prevent them manually entering any additional values that are not part of the options list - all while allowing duplicates. This is why create is disabled at the end.

My workaround is to adjust the condition in the description to:
if ((!self.settings.persist && self.userOptions.hasOwnProperty(value)) && (!self.settings.duplicates || self.items.indexOf(value) == -1))

@StephenLongville StephenLongville added the bug Something isn't working label Aug 22, 2024
Copy link

This issue has not been active in 120 days and has been marked "stale". Remove stale label or comment or this will be closed in 15 days

@github-actions github-actions bot added the stale No activity label Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale No activity
Projects
None yet
Development

No branches or pull requests

1 participant