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

How do u modify an existing Value without Being Forced to Delete then Add The Modification Back? #1176

Open
amiga-500 opened this issue Aug 26, 2024 · 2 comments
Assignees

Comments

@amiga-500
Copy link

So here is how i create my choices...

    keywordChoices = new Choices(document.getElementById('keywords'), {
        delimiter: ',',
        editItems: true,
        maxItemCount: -1,
        duplicateItemsAllowed: false,
        removeItemButton: true,
        shouldSortItems: true,
        sorter: function(a, b) {
            return a.label.toLowerCase().localeCompare(b.label.toLowerCase());
        },
        allowHTML: true,
        placeholderValue: 'Type a keyword or phrase.',
        items: keywordsArray
    });

But once i set items how do i modify existing ones?

Currently i am forced to do the following where i delete the key then i read it with a modified value/label:

keywordChoices.removeActiveItemsByValue(key);
 keywordChoices.setValue([{value: key, label: key}]);

Seems horribly inefficient. Surely, there has to be a way to udpate an existing value more easily.

@Xon
Copy link
Collaborator

Xon commented Aug 26, 2024

This is for a <input type="text> field correct?

The library doesn't currently have a way to update the existing choices/options/items

@amiga-500
Copy link
Author

This is for a <input type="text> field correct?

The library doesn't currently have a way to update the existing choices/options/items

Yup its for that field type. And thanks for the clarification. Ok, just had to check. Will write custom code to fix my issue now.

@Xon Xon self-assigned this Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants