Allow DLC to have date_finished set
This commit is contained in:
parent
db4c635260
commit
5b6762bc12
|
@ -2,7 +2,7 @@ import {
|
||||||
syncSelectInputUntilChanged,
|
syncSelectInputUntilChanged,
|
||||||
getEl,
|
getEl,
|
||||||
disableElementsWhenTrue,
|
disableElementsWhenTrue,
|
||||||
disableElementsWhenFalse,
|
disableElementsWhenValueNotEqual,
|
||||||
} from "./utils.js";
|
} from "./utils.js";
|
||||||
|
|
||||||
let syncData = [
|
let syncData = [
|
||||||
|
@ -21,7 +21,11 @@ function setupElementHandlers() {
|
||||||
"#id_name",
|
"#id_name",
|
||||||
"#id_related_purchase",
|
"#id_related_purchase",
|
||||||
]);
|
]);
|
||||||
disableElementsWhenFalse("#id_type", "game", ["#id_date_finished"]);
|
disableElementsWhenValueNotEqual(
|
||||||
|
"#id_type",
|
||||||
|
["game", "dlc"],
|
||||||
|
["#id_date_finished"]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", setupElementHandlers);
|
document.addEventListener("DOMContentLoaded", setupElementHandlers);
|
||||||
|
|
|
@ -75,6 +75,10 @@ function syncSelectInputUntilChanged(syncData, parentSelector = document) {
|
||||||
* @param {string} property - The property to retrieve the value from.
|
* @param {string} property - The property to retrieve the value from.
|
||||||
*/
|
*/
|
||||||
function getValueFromProperty(sourceElement, property) {
|
function getValueFromProperty(sourceElement, property) {
|
||||||
|
let source =
|
||||||
|
sourceElement instanceof HTMLSelectElement
|
||||||
|
? sourceElement.selectedOptions[0]
|
||||||
|
: sourceElement;
|
||||||
let source =
|
let source =
|
||||||
sourceElement instanceof HTMLSelectElement
|
sourceElement instanceof HTMLSelectElement
|
||||||
? sourceElement.selectedOptions[0]
|
? sourceElement.selectedOptions[0]
|
||||||
|
@ -138,16 +142,44 @@ function conditionalElementHandler(...configs) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function disableElementsWhenFalse(targetSelect, targetValue, elementList) {
|
function disableElementsWhenValueNotEqual(
|
||||||
|
targetSelect,
|
||||||
|
targetValue,
|
||||||
|
elementList
|
||||||
|
) {
|
||||||
return conditionalElementHandler([
|
return conditionalElementHandler([
|
||||||
() => {
|
() => {
|
||||||
return getEl(targetSelect).value != targetValue;
|
let target = getEl(targetSelect);
|
||||||
|
console.debug(
|
||||||
|
`${disableElementsWhenTrue.name}: triggered on ${target.id}`
|
||||||
|
);
|
||||||
|
console.debug(`
|
||||||
|
${disableElementsWhenTrue.name}: matching against value(s): ${targetValue}`);
|
||||||
|
if (targetValue instanceof Array) {
|
||||||
|
if (targetValue.every((value) => target.value != value)) {
|
||||||
|
console.debug(
|
||||||
|
`${disableElementsWhenTrue.name}: none of the values is equal to ${target.value}, returning true.`
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.debug(
|
||||||
|
`${disableElementsWhenTrue.name}: none of the values is equal to ${target.value}, returning true.`
|
||||||
|
);
|
||||||
|
return target.value != targetValue;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
elementList,
|
elementList,
|
||||||
(el) => {
|
(el) => {
|
||||||
|
console.debug(
|
||||||
|
`${disableElementsWhenTrue.name}: evaluated true, disabling ${el.id}.`
|
||||||
|
);
|
||||||
el.disabled = "disabled";
|
el.disabled = "disabled";
|
||||||
},
|
},
|
||||||
(el) => {
|
(el) => {
|
||||||
|
console.debug(
|
||||||
|
`${disableElementsWhenTrue.name}: evaluated false, NOT disabling ${el.id}.`
|
||||||
|
);
|
||||||
el.disabled = "";
|
el.disabled = "";
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
Loading…
Reference in New Issue