-
Notifications
You must be signed in to change notification settings - Fork 440
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
Adding tag on button click #524
Comments
I need to add support for this, because if you click on anything, you will look the current caret position and won't be able to inject a tag there. You need save last caret place in tagify, on |
See jsbin demo |
@yairEO thank you, but i have one more question, can i implement it using React? |
yes. this is my implement using React const settings = { const MixedModeTagify = () => {
}; export default MixedModeTagify; |
Hi @yairEO I think I found an issue in this demo: If you add multiple tags without iterate with the textarea you get tags inside tags May be it's the caret postion that it is still inside the tag, idk. I noticed this issue because I am facing a similar problem |
@pedroR - Thank you for pointing it out to me, I've fixed the demo var input = document.querySelector('textarea')
var tagify = new Tagify(input, {
mode: "mix"
})
document.querySelector("button").addEventListener('click', ()=> {
var tagElm = tagify.createTagElem({ value:"my tag" })
tagify.injectAtCaret(tagElm)
var elm = tagify.insertAfterTag(tagElm) // <- adds space after the tag
tagify.placeCaretAfterNode(elm) // <- places the caret after the space
}) |
Hi @yairEO . I needed to two fixes for it to work properly.
// Initialize selection if necessary
if (!tagify.state.selection) {
$(tagify.DOM.input).focus();
tagify.setStateSelection();
}
tagify.injectAtCaret(''); // insert empty text node to fix trouble of missing ending space when empty
const tagData = { value:"my tag" };
const newTag = tagify.createTagElem(tagData);
tagify.injectAtCaret(newTag);
const elm = tagify.insertAfterTag(newTag) // adds space after the tag
tagify.placeCaretAfterNode(elm); // places the caret after the space |
I want to add tag in my
cursorcaret position after clicking a button in mix mode, i don't understand how to get caret index, because we use html + text in form, and I didn't found any working solution in SO for this case, can you pls help?The text was updated successfully, but these errors were encountered: