[ISSUE] choices.js dataset lost

This commit is contained in:
Marie Birner 2023-09-24 10:32:38 +02:00 committed by philipp
parent 57e540f450
commit f18b72ecef

View File

@ -19,9 +19,57 @@ document.addEventListener('DOMContentLoaded', function() {
});
function selectBoatChange() {
const boatSelect = document.querySelector('#boat_id');
if(boatSelect) {
boatSelect.addEventListener('change', function() {
const boatSelect = <HTMLSelectElement>document.querySelector('#boat_id');
const boatChoice = new Choices(boatSelect, {
loadingText: 'Wird geladen...',
noResultsText: 'Keine Ergebnisse gefunden',
noChoicesText: 'Keine Ergebnisse gefunden',
itemSelectText: 'Zum Auswählen klicken',
callbackOnCreateTemplates: function () {
console.log('here');
return {
option: ({ label, value, customProperties, active, disabled, }: Item) => {
const opt: HTMLOptionElement = Choices.defaults.templates.option.call(
this,
{ label, value, customProperties, active, disabled }
);
// We get the original <option> from choicejs
const originalOption: HTMLOptionElement = this._presetOptions.filter(
(option: HTMLOptionElement) => option.value === value
)[0];
const selectedValue = Number(originalOption.dataset.amount_seats);
const rowers = Number(selectedValue) - 1;
console.log(rowers);
choiceObjects['newrower'].config.maxItemCount = rowers;
choiceObjects['newrower'].removeActiveItems(rowers);
console.log(choiceObjects['newrower']);
(rowers === 0 ? choiceObjects['newrower'].disable() : choiceObjects['newrower'].enable());
return opt;
}
}
}
});
choiceObjects[boatSelect.id] = boatChoice;
const shipmasterSelect = <HTMLSelectElement>document.querySelector('#shipmaster');
const shipmasterChoice = new Choices(shipmasterSelect, {
loadingText: 'Wird geladen...',
noResultsText: 'Keine Ergebnisse gefunden',
noChoicesText: 'Keine Ergebnisse gefunden',
itemSelectText: 'Zum Auswählen klicken',
});
choiceObjects[shipmasterSelect.id] = shipmasterChoice;
if(boatChoice) {
boatChoice.passedElement.element.addEventListener('change', function(event) {
console.log(event);
const selectedElement = boatSelect as HTMLSelectElement;
const opt = selectedElement.options[selectedElement.selectedIndex];
const selectedValue = (<HTMLOptionElement>opt).dataset.amount_seats;