I am building an application which will generate a dynamic form for customer feedback reception. Now while adding fields to the form, individual fields have validation rules inlcuding length
and type
rules, there is also going to be a property on each validation rule, which will determine if that particular rule should be parsed while validating the fields.
I have a Vue data property called fields
, which has an object for each field. It looks like this:
export default {
data() {
return {
fields: [{
label: 'Email',
validation: {
length: {
add: 0, // 0 for false, 1 for true
min: 0, // minimum length
max: 0 // maximum length
}
}
}]
}
}
}
Now for enabling the user to select whether validation rule should be enabled or disabled (i.e length.add = 1 or 0
) , I have a a select
element with two options for their respective values (0
and 1
). Here is the template code:
<div v-for="(field, index) in fields">
<div v-for="(rule, key) in field.validation">
<select class="form-control" v-model="fields[index].validation[key].add">
<option :value="1">Enabled</option>
<option :value="0">Disabled</option>
</select>
</div>
</div>
Everything is working fine such as the v-model
on select
is mutating the value in the data property, but the select
isn't showing the default value which is selected, here is what it looks like after rendering:
Can someone please tell me why isn't it working? I also tried replacing v-model
with the value
attribute, but no luck!