impress/app/assets/javascripts/items/show.js
Emi Matchu c06c297174 Extremely lo-fi new species face picker for simplified item previews
The basics are working great! There's a few known missing things though:
- Add reasonable noscript behavior
- Disable options where there's no valid appearance
- Lay it out actually _good_, instead of just images dumped there
2024-09-03 13:30:12 -07:00

15 lines
662 B
JavaScript

// 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);
}
});