The selected item does not erase after selecting a new


#1

Hello ,
I have a select2 field where I can choose a option. When I select a new one, the old one doesn’t erase. They just Keep getting more and more.

This is the code:
<select2 type="text" v-on:input="updateBereiche" :options="bereiche" class="form-control" id="bereichsauswahl" multiple=false>

And this:

` methods: {
updateBereiche: function(value) {
value = $(’#bereichsauswahl’).select2(‘data’);
console.log(value);
this.$store.commit(‘setBereichInput’, value.id)

    }
}`

Can someone tell me what the promblem is?


#2

What framework are you using? The Select2 widget is designed to be initialized on an HTML <select> element. It appears you’re trying to use a custom HTML element (called “select2”), but I can’t tell what that renders into.

Can you post your code on CodePen or JSFiddle so I can see what it’s doing?


#3

Hi,
thanks for the reply.
In the meantime I found the cause.
There was in a component a div element where i did not belong.

All is fine now.


#4

Great! I’m glad you found the problem.