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

Toggle Tagify Inputs Between Editable and Non-Editable Modes #1376

Open
abalter opened this issue Sep 10, 2024 · 0 comments
Open

Toggle Tagify Inputs Between Editable and Non-Editable Modes #1376

abalter opened this issue Sep 10, 2024 · 0 comments

Comments

@abalter
Copy link

abalter commented Sep 10, 2024

I know there are examples, but I don't seem to be smart enough to figure out what to do.

I'm working on a JavaScript application where users can create notes with tags. I'm using the Tagify library to enhance the tag input functionality.

I'm initializing the Tagify input as follows:

const tagInput = document.querySelector('.note-tags');
const tagify = new Tagify(tagInput, {
    whitelist: ['example-tag-1', 'example-tag-2', 'example-tag-3'],
    enforceWhitelist: false,
    dropdown: {
        position: 'input',
        enabled: 0 // Always show suggestions
    }
});
tagify.addTags(['example-tag-1', 'example-tag-2']);

I need to toggle this Tagify input between:

  1. Editable mode: Users can add/remove tags.
  2. Non-editable mode: Users cannot modify the tags.

Here’s my attempt to toggle the editable state:

function setTagifyEditMode(editable) {
    const tagifyElement = document.querySelector("[class^='tagify']");
    if (editable) {
        tagifyElement.removeAttribute('contenteditable');
        tagify.settings.readonly = false;
    } else {
        tagifyElement.setAttribute('contenteditable', 'false');
        tagify.settings.readonly = true;
    }

    tagify.DOM.input.readOnly = !editable;

    // Updating the settings
    tagify.update();
}

// Example usage
setTagifyEditMode(false); // Making the Tagify input non-editable

Despite attempting the changes above, the Tagify input remains editable even in non-editable mode. How can I correctly toggle the Tagify input between editable and non-editable states?

Any guidance or suggestions would be greatly appreciated. Thank you!

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