[BUGFIX] js errors

This commit is contained in:
Marie Birner 2023-09-27 13:52:15 +02:00
parent 670351397e
commit 74c0db4e75

View File

@ -20,46 +20,51 @@ document.addEventListener('DOMContentLoaded', function() {
function selectBoatChange() { function selectBoatChange() {
const boatSelect = <HTMLSelectElement>document.querySelector('#boat_id'); 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 () {
return {
option: ({ label, value, customProperties, active, disabled, }: any) => {
const opt: HTMLOptionElement = Choices.defaults.templates.option.call(
this,
{ label, value, customProperties, active, disabled }
);
// We get the original <option> from choicejs if(boatSelect) {
const originalOption: HTMLOptionElement = this._presetOptions.filter( const boatChoice = new Choices(boatSelect, {
(option: HTMLOptionElement) => option.value === value loadingText: 'Wird geladen...',
)[0]; noResultsText: 'Keine Ergebnisse gefunden',
noChoicesText: 'Keine Ergebnisse gefunden',
const rowers = Number(originalOption.dataset.amount_seats) - 1; itemSelectText: 'Zum Auswählen klicken',
callbackOnCreateTemplates: function () {
setMaxAmountRowers(rowers); return {
option: ({ label, value, customProperties, active, disabled, }: any) => {
const opt: HTMLOptionElement = Choices.defaults.templates.option.call(
return opt; 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 rowers = Number(originalOption.dataset.amount_seats) - 1;
setMaxAmountRowers(rowers);
return opt;
}
}
} }
} } as any);
} as any);
choiceObjects[boatSelect.id] = boatChoice;
choiceObjects[boatSelect.id] = boatChoice; }
const shipmasterSelect = <HTMLSelectElement>document.querySelector('#shipmaster'); const shipmasterSelect = <HTMLSelectElement>document.querySelector('#shipmaster');
const shipmasterChoice = new Choices(shipmasterSelect, { if(shipmasterSelect) {
loadingText: 'Wird geladen...', const shipmasterChoice = new Choices(shipmasterSelect, {
noResultsText: 'Keine Ergebnisse gefunden', loadingText: 'Wird geladen...',
noChoicesText: 'Keine Ergebnisse gefunden', noResultsText: 'Keine Ergebnisse gefunden',
itemSelectText: 'Zum Auswählen klicken', noChoicesText: 'Keine Ergebnisse gefunden',
}); itemSelectText: 'Zum Auswählen klicken',
});
choiceObjects[shipmasterSelect.id] = shipmasterChoice;
choiceObjects[shipmasterSelect.id] = shipmasterChoice;
}
} }
function setMaxAmountRowers(rowers: number){ function setMaxAmountRowers(rowers: number){