import { Controller } from '@hotwired/stimulus'; /* * Collects the ticked rows (+ their quantity) from a DataTable and POSTs them * to the combat tracker. * *
* *
*/ export default class extends Controller { static values = { url: String, token: String }; submit() { const picks = [...document.querySelectorAll('.track-check:checked')].map((cb) => { const qtyEl = cb.closest('.track-pick')?.querySelector('.track-qty'); const qty = Math.max(1, Math.min(50, parseInt(qtyEl?.value ?? '1', 10) || 1)); return { id: cb.value, qty }; }); if (picks.length === 0) { window.alert('Tick at least one enemy first.'); return; } const form = document.createElement('form'); form.method = 'post'; form.action = this.urlValue; form.insertAdjacentHTML('beforeend', ``); picks.forEach((p, i) => { form.insertAdjacentHTML('beforeend', `` + ``); }); document.body.appendChild(form); form.requestSubmit(); } }