2024-09-03 13:23:58 -07:00
|
|
|
// When the species *face* picker changes, update and submit the main picker form.
|
|
|
|
document.addEventListener("click", (e) => {
|
|
|
|
if (!e.target.matches(".species-face-picker input[type=radio]")) return;
|
|
|
|
|
|
|
|
try {
|
|
|
|
const mainPicker = document.querySelector("#item-preview .species-color-picker");
|
|
|
|
const mainSpeciesField =
|
|
|
|
mainPicker.querySelector("[name='preview[species_id]']");
|
|
|
|
mainSpeciesField.value = e.target.value;
|
|
|
|
mainPicker.requestSubmit(); // `submit` doesn't get captured by Turbo!
|
|
|
|
} catch (error) {
|
|
|
|
e.preventDefault();
|
|
|
|
console.error("Couldn't update species picker: ", error);
|
|
|
|
}
|
|
|
|
});
|
2024-09-03 13:46:29 -07:00
|
|
|
|
|
|
|
// Now that the face picker is ready to go, mark it as usable.
|
|
|
|
for (const options of document.querySelectorAll(".species-face-picker-options")) {
|
|
|
|
options.removeAttribute("inert");
|
|
|
|
options.removeAttribute("aria-hidden");
|
|
|
|
}
|