2023-11-14 20:09:43 +00:00
|
|
|
import {
|
|
|
|
syncSelectInputUntilChanged,
|
|
|
|
getEl,
|
|
|
|
disableElementsWhenTrue,
|
2023-11-20 20:20:10 +00:00
|
|
|
disableElementsWhenValueNotEqual,
|
2023-11-14 20:09:43 +00:00
|
|
|
} from "./utils.js";
|
2023-11-09 13:49:00 +00:00
|
|
|
|
|
|
|
let syncData = [
|
|
|
|
{
|
2023-11-14 18:27:00 +00:00
|
|
|
source: "#id_edition",
|
|
|
|
source_value: "dataset.platform",
|
|
|
|
target: "#id_platform",
|
|
|
|
target_value: "value",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
syncSelectInputUntilChanged(syncData, "form");
|
|
|
|
|
2023-11-14 20:09:43 +00:00
|
|
|
function setupElementHandlers() {
|
|
|
|
disableElementsWhenTrue("#id_type", "game", [
|
|
|
|
"#id_name",
|
|
|
|
"#id_related_purchase",
|
|
|
|
]);
|
2023-11-20 20:20:10 +00:00
|
|
|
disableElementsWhenValueNotEqual(
|
|
|
|
"#id_type",
|
|
|
|
["game", "dlc"],
|
|
|
|
["#id_date_finished"]
|
|
|
|
);
|
2023-11-14 20:09:43 +00:00
|
|
|
}
|
2023-11-14 18:27:00 +00:00
|
|
|
|
2023-11-14 20:09:43 +00:00
|
|
|
document.addEventListener("DOMContentLoaded", setupElementHandlers);
|
2023-11-16 18:03:16 +00:00
|
|
|
document.addEventListener("htmx:afterSwap", setupElementHandlers);
|
2023-11-14 18:27:00 +00:00
|
|
|
getEl("#id_type").onchange = () => {
|
2023-11-14 20:09:43 +00:00
|
|
|
setupElementHandlers();
|
|
|
|
};
|
2023-11-16 19:33:56 +00:00
|
|
|
|
2023-11-20 20:15:18 +00:00
|
|
|
document.body.addEventListener("htmx:beforeRequest", function (event) {
|
2023-11-16 19:33:56 +00:00
|
|
|
// Assuming 'Purchase1' is the element that triggers the HTMX request
|
2023-11-20 20:15:18 +00:00
|
|
|
if (event.target.id === "id_edition") {
|
|
|
|
var idEditionValue = document.getElementById("id_edition").value;
|
2023-11-16 19:33:56 +00:00
|
|
|
|
2023-11-20 20:15:18 +00:00
|
|
|
// Condition to check - replace this with your actual logic
|
|
|
|
if (idEditionValue != "") {
|
|
|
|
event.preventDefault(); // This cancels the HTMX request
|
|
|
|
}
|
2023-11-16 19:33:56 +00:00
|
|
|
}
|
|
|
|
});
|