33 lines
1023 B
JavaScript
33 lines
1023 B
JavaScript
import {Controller} from "@hotwired/stimulus";
|
|
|
|
|
|
export default class extends Controller {
|
|
static targets = ['ticket', 'afterShowTicket', 'kid12yo', 'kid6yo', 'meat', 'vegetarian', 'vegan', 'error']
|
|
|
|
connect() {
|
|
this.element.addEventListener('submit', (e) => this.submit(e))
|
|
}
|
|
|
|
submit(e) {
|
|
e.preventDefault();
|
|
const ticketCount = this.getTotalTicketCount();
|
|
const foodCount = this.getTotalFoodCount();
|
|
|
|
if (foodCount > ticketCount) {
|
|
this.errorTarget.textContent = 'Sie können nicht mehr Essen als Tickets bestellen';
|
|
}
|
|
}
|
|
|
|
getTotalTicketCount() {
|
|
return parseInt(this.ticketTarget.value)
|
|
+ parseInt(this.kid12yoTarget.value)
|
|
+ parseInt(this.kid6yoTarget.value)
|
|
+ parseInt(this.afterShowTicketTarget.value);
|
|
}
|
|
|
|
getTotalFoodCount() {
|
|
return parseInt(this.meatTarget.value)
|
|
+ parseInt(this.vegetarianTarget.value)
|
|
+ parseInt(this.veganTarget.value);
|
|
}
|
|
} |