Skip to content

Tag-added event not triggering if value is added programatically #146

Description

@Marchiuzzz

I'm not sure if this is a bug or if I'm doing something wrong or perhaps that's the intended behavior but if I have a setup like this:

<template>
    <div>
        <tags-input element-id="tags"
            v-model="selectedTags"
            :existing-tags="availableTags"
            :before-adding-tag="checkIfExists"
            typeahead-style="dropdown"
            placeholder="Tags"
            @tag-removed="remove"
            @tag-added="add"
            :typeahead="true" v-if="!loading"></tags-input>
    </div>
</template>
<script>
import Tag from '../Models/Tag'
export default {
    ...
    data(){
        return {
            tagLabel: 'tags',
            tagInput: '',
            selectedTags: [],
            loading: true,
        }
    },
    methods:{
        checkIfExists(item){
            if(!item.key){
                if(confirm(window.translate('dictionary.addNewTag'))){
                    axios.post('/api/tags/create', {tagname: item.value})
                    .then(response => {
                        var respTag = response.data.data;
                        Tag.insert({
                            data: respTag
                        });
                        this.selectedTags.push(respTag);
                    });
                }
                return false;
            }else{
                return true;
            }
        },
    }
}
</script>

As you can see, I append a new tag to tags list with this line this.selectedTags.push(respTag); however, it does not fire a "tag-added" event

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions