I have a form that adds new products to a database. The category, I want to have pre filled in the form. I use :value
to bind the category but the form requires v-model
to send the form data.
I know the use of v-model overwrites the use of :value
.
So instead of this code:
<b-form-input v-model="productCategory" :value="category.name />
I am looking for a way that would pass on the category.name
from the v-for
object to the productCategory
property on submit of the form.
I found this answer: Pass value of input to v-model but I still have trouble coming to a solution.
Can someone please help.
EDIT based on the answer by @caseyjoneal I have edited my question to provide more insight in the code.
Defined properties:
data() {
return {
products: [],
categories: [],
category: null,
name: null,
price: null,
productCategory: null,
productImage: null,
imageUrl: null,
description: null,
selected: "9",
btwOptions: [
{ value: "9", text: "9% BTW" },
{ value: "21", text: "21% BTW" }
]
}
}
V-for loop that loads a tab for every category from the db. Every tab has a modal inside which loads a form to add a product to the db. Since there is a tab for every category and a modal in every category I wanted to category field to be pre filled.
I have tried the suggestion from @caseyjoneal but I did not gave the wished result. No category was stored to the db.
<b-tab v-for="category in categories" v-bind:title="category.name" :key="category.id">
<b-modal>
<form>
<b-form-group label-cols-sm="3" label="Categorie:" label-align-sm="right" label-for="nestedCategory">
<div hidden>{{category.name}}:{{productCategory[category]}}</div>
<b-form-input id="nestedCategory" :placeholder="category" v-model="productCategory" readonly/>
</b-form-group>
</form>
</b-modal>
</b-tab>
So I am looking for a solution to achieve the equivalent of:
<b-form-input id="nestedCategory" v-model="productCategory" :value="category.name readonly/>