My goal is to connect a select box with an input field. The select box contains pre-defined options, and when an option is selected, it should appear in the input field. Additionally, if the user types text into the input field, a new dynamic select option should be created if it does not match any of the pre-defined options.
<div class="col-md-2 text-center">
<select class="form-control" v-model="selected">
<option v-for="item in inventory" :value="item" :key="item.id">
@{{ item.name }}
</option>
</select>
<p>
@{{ selected.id}}
</p>
</div>
<input v-model="inputBind" placeholder="," type="text" class="form-control">
In addition:
new Vue({
el:'#app',
data:{
inputBind:'',
inventory: [
{name: 'MacBook Air', id: 1},
{name: 'MacBook Pro', id: 2},
{name: 'Lenovo W530', id: 3},
{name: 'Acer Aspire One', id: 4}
],
selected: 2
},
created: function() {
this.selected = this.inventory.find(i => i.id === this.selected);
},