Good morning,
I have the following form:
When you click the 'New Item' button, a new textfield is added to the relevant section. If you click the 'New Section' button, a new section is created. When you click the 'X' in the top right of the section, the section successfully deletes. However, I'm trying to implement the 'X' below (on the right) of each 'Addition' Text Field. I thought, it would be the inverse code of adding an additional text field, but using the splice() function. This however doesn't work.
My code is below, any help would be greatly appreciated.
var app = new Vue({
el: '.container',
data: {
sections: [{
item: '',
additionals: []
}]
},
methods: {
addNewSection() {
this.sections.push({
item: '',
additionals: []
})
},
addNewItem(id) {
this.sections[id].additionals.push({
item: ''
})
}
}
})
<script src="https://cdn.jsdelivr.net/vue/latest/vue.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div id="app">
<div class="container">
<button class="btn btn-success mt-5 mb-5" @click="addNewSection">
New Deal Section
</button>
<div class="card mb-3" v-for="(section, index) in sections">
<hr>
<div class="card-body">
<button class="btn btn-success mt-5 mb-5" @click="addNewItem(index)">
New Item
</button>
<span class="float-right" style="cursor:pointer">
X
</span>
<h4 class="card-title">Deal section {{ index + 1}}</h4>
<div class="employee-form" v-for="(addition, index) in section.additionals">
<input type="text" class="form-control mb-2" placeholder="Item" v-model="addition.item">
</div>
<div class="employee-form">
<input type="text" class="form-control mb-2" placeholder="Item" v-model="section.item">
</div>
</div>
</div>
</div>
</div>

When you click the 'X' in the top right of the section, the section successfully deletes.it doesn't delete in your fiddle :/this.sections[index].additionals.splice(indexSection,1)notthis.sections[index].additionals[indexSection].splice(indexSection,1)😊