I need to duplicate a text input field when user clicks a button "add another" and increment the index on the new field. It's similar to this other question but that solution didn't increment anything.
What I have duplicates the field and increments the index, but it affects all the indexes, not just the newest. (thanks Roy J for the tip)
Here's my template:
<div id="app">
<template v-for="slot in timeslots">
<div><input type="text" name="performances[@{{ count }}][timestamp]" v-model="slot.timestamp" placeholder="index @{{ count }}"></div>
</template>
<span class="add green btn" @click="addAnother"><i class="fa fa-plus-circle"></i> Add another</span>
<pre>@{{ timeslots | json }}</pre>
</div>
Here's what I have in my Vue JS:
new Vue({
el: '#app',
data: {
timeslots: [
{
timestamp: '',
count: 0
}
],
count: 0
},
methods: {
addAnother: function(){
this.timeslots.push({
timestamp: '',
count: this.count++
});
}
}
});
this.count++?addAnother? Doesn't validate.