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.

[form-select] Cannot set value when return-object="true"

See original GitHub issue

It appears that one cannot set the v-model value when return-object is true.

https://jsfiddle.net/bootstrapvue/osty8mc8/

localvalue (inside b-form-select) expects to be the value field of the option(s), but the watcher for value, blindly passes the v-model value to localvalue, which is not what should be expected.

Does anyone actually use the return-object feature? Trying to get it to work on a two-way v-model might be a bit of code overhead,

When not in return-object mode, it is also possible to programmatically select a disabled option (which should not be allowed)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jmjfcommented, Jul 24, 2017

I ended up with something like the code below, which sounds similar to what you describe. This solution works, seems simple, and is probably best left to the developer. The component’s default input event works fine for simple types, but for objects, this seems reasonable and gets me an object back in v-model. The options array is a computed property, so can be customized as needed.

<b-form-select 
  v-model="optionId"
  :options="options"
  text-field="shortName"
  value-field="id"
  @input="inputSelect" 
>
</b-form-select>
methods: {
  inputSelect () {
    this.$emit('input', this.options.find(item => item.id === this.optionId))
  }
}
0reactions
omarjebaricommented, Apr 2, 2020

I would just use vue-select then apply the same css classes that vue-bootstrap applies. vue-select easily handles objects so i dont know why <b-form-select> can’t.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-select not updating selected value on initial select
value type must be the same as the first argument of onChange callback: value={region} onChange={(item) => { console.log(item); // set item ...
Read more >
[Solved]-Vuetify autocomplete component: set value-Vue.js
Following snippet worked for me: <v-autocomplete [...] :filter="filter" :return-object="true" > <template slot="selection" slot-scope="data"> ...
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