v-model value not respected on start
See original GitHub issueHey!
Thank you very much for this very easy to use and customizable component! 🎉
It works very well so far, except showing initial selected values. In the example below I load a list of users and their associated roles and a list of all roles as well.
The user.role_ids
property is an array with only one value [ 1 ]
, but nothing is displayed in the Multiselect
component.
When selecting one of the options in the Multiselect dropdown, the user.role_ids
changes and the entry is displayed in the components div.
But I can see no difference in the result in user.role_ids
.
Is there something I am missing or using the component the wrong way?
Example:
<template>
<div>
<div v-for="user in state.users" :key="user.id">
{{ user }}
// { "id": 1, "name": "Admin", "email": "....", "created_at": "2017-12-20T09:47:36.000000Z",
// "updated_at": "2021-01-26T14:19:00.000000Z", "role_ids": [ 1 ],
// "roles": [ { "id": 1, "name": "admin", "display_name": "Administrator", "description": "Project Administrator",
// "created_at": "2017-12-20T09:47:35.000000Z", "updated_at": "2017-12-20T09:47:35.000000Z" } ] }
{{ user.role_ids }}
// [ 1 ]
{{ state.roles }}
// [ { "id": 1, "name": "admin", "display_name": "Administrator", "description": "Project Administrator",
// "created_at": "2017-12-20T09:47:35.000000Z", "updated_at": "2017-12-20T09:47:35.000000Z" },
// { "id": 2, "name": "guest", "display_name": "Guest", "description": "Guest User",
// "created_at": "2017-12-20T09:47:35.000000Z", "updated_at": "2017-12-20T09:47:35.000000Z" } ]
<multiselect
v-model="user.role_ids"
:label="'display_name'"
:track-by="'display_name'"
:valueProp="'id'"
:mode="'tags'"
:searchable="true"
:options="state.roles"
:placeholder="t('main.user.add-role-placeholder')">
</multiselect>
</div>
</div>
</template>
<script>
import {
computed,
reactive,
} from 'vue';
export default {
setup() {
const state = reactive({
userList: computed(_ => store.getters.users),
roles: computed(_ => store.getters.roles),
});
return {
state
}
}
</script>
Issue Analytics
- State:
- Created 3 years ago
- Comments:6
Top Results From Across the Web
Input value not being set with v-model - Stack Overflow
I'm trying to set a the value in an input with Vue by using a v-model. I am using the Vue Typeahead library....
Read more >Issues with v-model.number · Issue #7136 · vuejs/vue - GitHub
What is actually happening? ... Input value is cleared sometimes, v-model.number returns "" for "" and partially typed numbers. This issue started ...
Read more >Form Input | Components - BootstrapVue
Create various type inputs such as: text, password, number, url, email, search, range, date and more.
Read more >Render Functions & JSX | Vue.js
Props with names that start with on followed by an uppercase letter are treated ... The v-model directive is expanded to modelValue and...
Read more >Using v-model in Vue 3 to build complex forms - LogRocket Blog
The v-model directive uses distinct properties and emits different events for different input elements by default: value property and input ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Added a patch in
1.3.1
wherenextTick
is no longer required.@adamberecz hi, i have the same problem, when getting options asynchronously (render select with empty options and then update otions)
@v1r0x, hi! You can fix your problem by adding 'v-if=state.roles.length" to multiselect component