[ISSUE] choices.js dataset lost
This commit is contained in:
parent
3c040fc979
commit
72f172e4a2
@ -19,9 +19,57 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function selectBoatChange() {
|
function selectBoatChange() {
|
||||||
const boatSelect = document.querySelector('#boat_id');
|
const boatSelect = <HTMLSelectElement>document.querySelector('#boat_id');
|
||||||
if(boatSelect) {
|
const boatChoice = new Choices(boatSelect, {
|
||||||
boatSelect.addEventListener('change', function() {
|
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 selectedElement = boatSelect as HTMLSelectElement;
|
||||||
const opt = selectedElement.options[selectedElement.selectedIndex];
|
const opt = selectedElement.options[selectedElement.selectedIndex];
|
||||||
const selectedValue = (<HTMLOptionElement>opt).dataset.amount_seats;
|
const selectedValue = (<HTMLOptionElement>opt).dataset.amount_seats;
|
||||||
|
Loading…
Reference in New Issue
Block a user