Skip to content

Select is not updating the label when the v-model attribute is cleared #26

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

Open
laurengriffin opened this issue Jan 31, 2020 · 2 comments

Comments

@laurengriffin
Copy link

Hi,

I have this following code

<div
  v-for="(selected, index) in data"
  :key="index"
>
  <vue-select
    v-model="data[index]"
    :data="dataOptions"
    placeholder="Select"
  >
    <vue-option
      v-for="option in dataOptions"
      :key="option.value"
      :value="option.value"
      :label="option.label"
    />
  </vue-select>
</div>

However, when I clear the data[index] for the corresponding index, the data is updated correctly but the label displayed stays the same and gives the illusion that the data wasn't cleared. Is there a way to update the label when the data in the v-model object is changed?

@varave
Copy link

varave commented Mar 4, 2020

@laurengriffin hi, maybe your problem will be solved this: https://vuejs.org/v2/guide/reactivity.html#Async-Update-Queue

@varave
Copy link

varave commented Mar 13, 2020

@antonreshetov the problem is on this line

, if this.value is empty, then you need to clear this.selected. I fixed this code and it worked:

setInitValue () {
  if (this.multiple) {
    this.selected = this.value.map(item => {
      return this.data.find(i => i.value === item)
    })
  } else if (this.value !== '') {
    this.selected = this.data.find(item => item.value === this.value)
  } else {
    this.selected = {}
  }
},

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

2 participants