Fix ticket quantity buttons on event page - Remove syntax error in ticket card component and improve error handling in ticket cart controller

This commit is contained in:
kbe
2025-08-28 20:56:48 +02:00
parent be3d80e541
commit b9576b91f5
2 changed files with 23 additions and 2 deletions

View File

@@ -16,6 +16,11 @@ export default class extends Controller {
const ticketTypeId = event.params.ticketTypeId
const max = parseInt(event.params.max)
const input = this.quantityTargetFor(ticketTypeId)
if (!input) {
console.error(`Could not find input for ticket type ID: ${ticketTypeId}`)
return
}
const current = parseInt(input.value) || 0
if (current < max) {
@@ -27,6 +32,11 @@ export default class extends Controller {
decreaseQuantity(event) {
const ticketTypeId = event.params.ticketTypeId
const input = this.quantityTargetFor(ticketTypeId)
if (!input) {
console.error(`Could not find input for ticket type ID: ${ticketTypeId}`)
return
}
const current = parseInt(input.value) || 0
if (current > 0) {
@@ -38,6 +48,12 @@ export default class extends Controller {
updateQuantityFromInput(event) {
const input = event.target
const ticketTypeId = input.dataset.ticketTypeId
if (!ticketTypeId) {
console.error('Missing ticket type ID on input element')
return
}
const max = parseInt(input.max)
const quantity = parseInt(input.value) || 0
@@ -308,6 +324,10 @@ export default class extends Controller {
// Helper method to find quantity input by ticket type ID
quantityTargetFor(ticketTypeId) {
return document.querySelector(`#quantity_${ticketTypeId}`)
const element = document.querySelector(`#quantity_${ticketTypeId}`)
if (!element) {
console.warn(`Could not find quantity input for ticket type ID: ${ticketTypeId}`)
}
return element
}
}