question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multi select cleared after select

See original GitHub issue

Hi, In my component I pass via props data for multi-select when I tried to select other data my select whas cleared fully :

<template>
  <div>
    <b-form-group label="Rôle: ">
      <b-form-select
        @change="emit"
        class="mb-3"
         v-model="value"
         id="form_roles"
          aria-describedby="choicesLiveFeedback"
          :state="formState"
         :multiple="true">
        <option :value="null">Select options</option>
        <option v-for="(role, index) in roles" :key="index" :value="role" >{{ role }}</option>
      </b-form-select>
      <b-form-invalid-feedback id="choicesLiveFeedback" :style="formStyle">
        {{ state }}
      </b-form-invalid-feedback>
    </b-form-group>
  </div>
</template>
<script>
export default {
  name: 'UserRole',
  props: ['value', 'state'],
  data () {
    return {
      roles: [],
      selected: [],
    }
  },
  watch: {
    value () {
      // if (this.selected !== this.value){
       // this.selected = this.value
      // }
    }
  },
  computed: {
      formState () {
        if (this.state !== undefined && this.state.length > 0) {
          return false
        }
      },
      formStyle () {
        if (!this.formState){
          return 'display: block'
        }
      }
    },
  methods: {
    emit (event) {
      this.$emit('input', [event])
    }
  },
  created () {
    // console.log(this.value);
    this.$http.get('/api/rest/securtity/roles').then(
      response => {
        this.roles = response.body
      }
    )
  }
}
</script>

at every test select was empty in view …

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:16 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
darkironcommented, Apr 27, 2018

to update parent object ? maybe ?

1reaction
emanuelmutschlechnercommented, Apr 27, 2018

@darkiron Your implementation has some flaws. Make sure to check Vue documentation on how to create a custom component that works with v-model as you expect it. https://vuejs.org/v2/guide/components-custom-events.html#Customizing-Component-v-model

Check my example below, hope this helps https://codesandbox.io/s/9zj7943prr

Read more comments on GitHub >

github_iconTop Results From Across the Web

Quick way to clear all selections on a multiselect enabled ...
Simply find all the selected <option> tags within your <select> and remove the selected attribute: $("#my_select option:selected").removeAttr("selected");.
Read more >
Selection options clear in multi-select after a selection is made ...
I am a beginner with React using react-select to list a bunch of account objects but my options list clears after any one...
Read more >
How to Clear or (Delete ) Selected items in Multiselect ...
Forum Thread - How to Clear or (Delete ) Selected items in Multiselect Dropdown By Clicking on external Button? - ASP.NET Core -...
Read more >
How to clear multiselect selections
Since I am handling the form submission in the javascript, I need to clear the previously selected items. Selected options should get unselected....
Read more >
Angular ng-select - npm
When multiple = true, allows to set a limit number of selection. [hideSelected], boolean, false, no, Allows to hide selected items. [multiple] ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found