import { disableElementsWhenTrue, onSwap } from "./utils.js"; import type { SearchSelectChangeDetail } from "./search_select.js"; // Switch between a single bundle price and one price per game. The per-game // inputs are the selection-fields element; this only sets the policy: the // hidden pricing_mode the view reads, the element's "active" flag, and whether // the bundle Price field is shown. function applyPricingMode(separate: boolean): void { const pricingMode = document.querySelector("#id_pricing_mode"); if (pricingMode) pricingMode.value = separate ? "per_game" : "combined"; const selectionFields = document.querySelector("selection-fields"); if (selectionFields) selectionFields.setAttribute("active", separate ? "true" : "false"); const priceInput = document.querySelector("#id_price"); if (priceInput) { const wrapper = priceInput.closest("div"); if (wrapper) wrapper.classList.toggle("hidden", separate); } } // The games field is a SearchSelect widget (a
, not a instead. disableElementsWhenTrue("#id_type", "game", [ "#id_name", "#id_related_game [data-search-select-search]", ]); } onSwap("#id_type", (typeSelect) => { setupElementHandlers(); typeSelect.addEventListener("change", () => { setupElementHandlers(); }); });