Skip to content

Delimiter/Paste Questions #1306

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

Open
jflad17 opened this issue May 23, 2025 · 2 comments
Open

Delimiter/Paste Questions #1306

jflad17 opened this issue May 23, 2025 · 2 comments

Comments

@jflad17
Copy link

jflad17 commented May 23, 2025

I was curious how the delimiter is supposed to work in terms of when pasting in comma (or delimiter) separated values into a choices input?

My idea was that it allowed to copy paste text by delimiter that will split into many selections, but using the latest release, I can't seem to get that to work on a text input with no choices.

If that is not going to work, I can try to set it on a on change event or additem event, which shouldn't be that bad to do.

@jflad17
Copy link
Author

jflad17 commented May 23, 2025

I believe I did get this to work by using the change event. I haven't fully tested this though. Maybe this could be moved to a feature request?

let choicesInput = null;
choicesInput = new Choices("#element", {
    duplicateItemsAllowed: false,
    removeItemButton: true
});
choicesInput.passedElement.element.addEventListener("change"), function (e) {
    let selectedValues = [];
    
    // check if value entered includes comma
    if (e.detail.value.split(",").length > 0) {

        // check for any existing items and append to array
        if (choicesInput.getValue() != undefined) {
            for (const v of choicesInput.getValue()) {
                selectedValues.push(v);
            }
        }
        for (const v of e.detail.value.split(",")) {
            selectedValues.push(v);
        }
        choicesInput.removeActiveItems(); // remove the comma separated string ex "test,test2,test3"
        choicesInput.setValue(selectedValues);  // using above example, result is test test2 test3 as separate bubbles
    }
});

@jflad17
Copy link
Author

jflad17 commented May 23, 2025

I believe I did get this to work by using the change event. I haven't fully tested this though. Maybe this could be moved to a feature request?

let choicesInput = null;
choicesInput = new Choices("#element", {
    duplicateItemsAllowed: false,
    removeItemButton: true
});
choicesInput.passedElement.element.addEventListener("change"), function (e) {
    let selectedValues = [];
    
    // check if value entered includes comma
    if (e.detail.value.split(",").length > 0) {

        // check for any existing items and append to array
        if (choicesInput.getValue() != undefined) {
            for (const v of choicesInput.getValue()) {
                selectedValues.push(v);
            }
        }
        for (const v of e.detail.value.split(",")) {
            selectedValues.push(v);
        }
        choicesInput.removeActiveItems(); // remove the comma separated string ex "test,test2,test3"
        choicesInput.setValue(selectedValues);  // using above example, result is test test2 test3 as separate bubbles
    }
});

It looks like this would work initially but not final as existing check doesn't seem to work properly or something else. I will have to look into it more, probably by using the e inside of the function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant