Level 104
You are assigning true to this.checked here:
this.checked = true
So that block will always be executed.
delete is not an Array method; what is this.selectedServicesPrices
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, I have an array that's hold prices for selected prices, and a checkbox to see if we should add to the array or not. But I'm having that issue of if you click the box and then unclick it the price wound reduce. Any ideas how to fix that? Here is my method:
servicesToArray(object) {
if (this.checked = true) {
this.selectedServicesDesc.push(object.description);
this.selectedServicesPrices.push(object.price);
}
if (this.checked = false) {
this.selectedServicesPrices.delete(object.price, 1);
}
}
<input class="mr-2 leading-tight" type="checkbox" v-model="checked" @click="servicesToArray(service)">
<input class="mr-2 leading-tight" type="checkbox" :value="service.description" hidden>
<span class="font-normal text-white" v-text="service.description"></span>
Figured it out:
servicesToArray(object) {
if (this.checked) {
if (this.selectedServicesPrices.includes(object.price) && this.selectedServicesDesc.includes(object.description)) {
this.selectedServicesDesc.splice(object, 1);
this.selectedServicesPrices.splice(object, 1);
} else {
this.selectedServicesDesc.push(object.description);
this.selectedServicesPrices.push(object.price);
}
}
}
Please or to participate in this conversation.