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.

Selected option setting id value

See original GitHub issue

If there is a default value for vue-select it sets id value. it doesnt set label.

                                       <v-select 
                                            :options="agentList" 
                                            label="full_name" 
                                            v-model="$v.agent_id.$model">
                                           >
                                        </v-select>

image When I inspect from vue dev tools selectedValue appears as 1.

I expect to see full_name at first but it shows id value.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:7
  • Comments:10

github_iconTop GitHub Comments

2reactions
esl51commented, May 4, 2021

Just use the get-option-label prop: https://vue-select.org/api/props.html#getoptionlabel

<template>
  <vue-select
    :options="options"
    :reduce="item => item.id"
    :get-option-label="getLabel"
  />
</template>

<script>
export default {
  data: () => ({
    options: [
      { id: 1, label: 'Option 1' },
      { id: 2, label: 'Option 2' }
    ]
  }),
  methods: {
    getLabel (option) {
      if (typeof option === 'object') {
        return option.label
      }
      const optionObject = this.options.find(item => item.id.toString() === option.toString())
      if (optionObject) {
        return optionObject.label
      }
      return option
    }
  }
}
</script>
1reaction
HenrijsScommented, Apr 15, 2021

Same issue, any solution???

Yes. Vue Multiselect - https://vue-multiselect.js.org/

Works better and has more features.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get and set the value of a select menu using an ID
Getting the selected ID using the selectedIndex and options properties # ... The options property returns an HTMLOptionsCollection , an array-like ...
Read more >
How to set selected option of select element by its ID?
javascript - How to set selected option of select element by its ID? - Stack Overflow. Stack Overflow for Teams – Start collaborating...
Read more >
How to set the default value for an HTML <select> element
The default value of the select element can be set by using the 'selected' attribute on the required option. This is a boolean...
Read more >
HTML option selected Attribute - W3Schools
The selected attribute is a boolean attribute. When present, it specifies that an option should be pre-selected when the page loads. The pre-selected...
Read more >
<select>: The HTML Select element - HTML - MDN Web Docs
Each <option> element should have a value attribute containing the data value to submit to the server when that option is selected. If...
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