JohMun / vue-tags-input

A tags input component for VueJS
http://www.vue-tags-input.com
952 stars 136 forks source link

A programmatic way to add a new tag #118

Open antonreshetov opened 4 years ago

antonreshetov commented 4 years ago

I use the custom dropdown as a suggestion. Is there any way to add a tag programmatically?

antonreshetov commented 4 years ago

Actually, I kind of figured it out. I created a new tag using the createTag helper. Then I called the addTag method by ref from <vue-tag-input> add pass new tag as argument. The question can be considered closed. The only thing we would like to see is as a method in the API of the component

kdeegan commented 4 years ago
import VueTagsInput, { createTag } from '@johmun/vue-tags-input';

let tag = createTag(tagName, [tagName]);

this.$refs.tags.addTag(tag);
SerlokPK commented 4 years ago

@kdeegan And how to use createTag method if I used component as plugin?

import Vue from 'vue'
import VueTagsInput from '@johmun/vue-tags-input'

Vue.use(VueTagsInput)
pskarlas commented 4 years ago

Jumping in having spent at least half a day banging my head why programmatically adding a tag via the helper wasn't working out for me. It's kinda funny/weird but when prop 'add-only-from-autocomplete' is set to true manually created tags won't be added. Switched the the prop to false everything rolled out as planned.

ps: IMHO this is not a desirable behaviour since programmatically added tags do not concern user input, therefore don't have to be whitelisted. Manual tag creation could bypass this check.

SerlokPK commented 4 years ago

@pskarlas Yes, problem is in addTag method, because they have some rules before adding, as u said, if 'add-only-from-autocomplete' is true, saving is not done. The best way to figure things out is to download their project and look through JS file