So I'm bringing in data from a CMS which is dynamically creating a title, a size and an input field which the user will be able to change.
When I increase the input value (1, 2, 3, 4 etc) the value changes in all inputs.
I need to take the number of individual inputs and do something with it.
I can kind of get this to work if I have my input type set to number but I want to keep it set to text so I can use custom increment and decrement buttons. As I said the buttons and the counter works but values clone to every input. I'm sure it's something to do with the increaseQty and decreaseQty functions..
I'm very new to Vue so be gentle. Thanks a million - Code below
<template>
<div>
<div id="step2items0" class="inventory">
<div class="inner-wrap">
<label>Choose Your {{ selected }} Items</label>
</div>
<div id="tabBtns" class="hr">
<div class="inner-wrap mobile-center">
<div v-for="(tab, index) in tabs" :key="index" @click="selectTab(tab)" class="tab" :class="selected_tab == tab ? 'selected' : ''" >
{{ tab }}
</div>
</div>
</div>
<div class="items-wrap">
<div class="item" v-for="(row, index) in items" :key="index">
<span class="lbl">{{ row.item_title }}</span>
<span class="input-wrap" style="display: flex; flex-direction: column">
<input type="text" name="item_m3" class="number" :value="row.item_m3"/>
<small>Item M3</small>
</span>
<span class="input-wrap">
<i id="decreaseQty" aria-hidden="true" class="fa fa-caret-left prev-btn" @click="decreaseQty"></i>
<input id="quantity" type="text" class="number" :value="quantity"/>
<i id="increaseQty" aria-hidden="true" class="fa fa-caret-right nxt-btn" @click="increaseQty"></i>
</span>
<div class="clear"></div>
</div>
</div>
</div>
</div>
</template>
<script>
module.exports = {
props: ["selected", "content", "value"],
data: function () {
return {
tabs: [],
selected_tab: "",
items: [],
quantity: 0,
};
},
computed: {
},
methods: {
//
increaseQty() {
this.quantity++;
console.log("AMOUNT -", this.quantity);
},
decreaseQty() {
if (this.quantity === 0) {
alert("Negative quantity not allowed");
} else {
this.quantity--;
console.log("AMOUNT -", this.quantity);
}
},
//
selectTab: function (value) {
console.log("TAB: ", value);
this.selected_tab = value;
const { content } = this;
let { items } = this;
content.forEach(function (row) {
if (row.room_name == value) {
items = row.item;
items.forEach(function (row) {
item_title = row.item_title;
item_m3 = row.item_m3;
console.log(" - ", item_title, " - ", item_m3);
});
}
});
this.items = items;
},
},
mounted: function () {
const { selected, content, tabs } = this;
let { selected_tab, items } = this;
console.log("SELECTED: ", selected);
if (selected === "Household") {
content.forEach(function (row) {
if (row.is_household == true) {
tabs.push(row.room_name);
if (selected_tab == "") {
selected_tab = row.room_name;
items = row.item;
items.forEach(function (row) {
item_title = row.item_title;
item_m3 = row.item_m3;
console.log(" - ", item_title, " - ", item_m3);
});
}
}
});
} else if (selected === "Business") {
content.forEach(function (row) {
if (row.is_business == true) {
tabs.push(row.room_name);
if (selected_tab == "") {
selected_tab = row.room_name;
items = row.item;
items.forEach(function (row) {
item_title = row.item_title;
item_m3 = row.item_m3;
console.log(row.room_name, " - ", item_title, " - ", item_m3);
});
}
}
});
}
this.selected_tab = selected_tab;
this.items = items;
},
};
</script>
<style scoped>
</style>