[TASK] improve rower select

This commit is contained in:
Marie Birner
2023-09-23 21:51:00 +02:00
committed by philipp
parent e3012be264
commit 17422a78a0
3 changed files with 43 additions and 17 deletions

View File

@ -14,8 +14,24 @@ document.addEventListener('DOMContentLoaded', function() {
replaceStrings();
initChoices();
initBoatActions();
selectBoatChange();
});
function selectBoatChange() {
const boatSelect = document.querySelector('#boat_id');
if(boatSelect) {
boatSelect.addEventListener('change', function() {
const selectedElement = boatSelect as HTMLSelectElement;
const opt = selectedElement.options[selectedElement.selectedIndex];
const selectedValue = (<HTMLOptionElement>opt).dataset.amount_seats;
const rowers = Number(selectedValue) - 1;
choiceObjects['newrower'].config.maxItemCount = rowers;
choiceObjects['newrower'].removeActiveItems(rowers);
(rowers === 0 ? choiceObjects['newrower'].disable() : choiceObjects['newrower'].enable())
});
}
}
function initBoatActions() {
const boatSelects = document.querySelectorAll('.boats-js[data-onclick="true"]');
if(boatSelects) {
@ -25,6 +41,7 @@ function initBoatActions() {
const rowers = Number(select.dataset.seats) - 1;
choiceObjects['newrower'].config.maxItemCount = rowers;
choiceObjects['newrower'].removeActiveItems(rowers);
(rowers === 0 ? choiceObjects['newrower'].disable() : choiceObjects['newrower'].enable());
}
});
});