import { Controller } from '@hotwired/stimulus'; export default class extends Controller { static classes = ['disabled']; static targets = ['checkbox']; static values = { maxSelectionsCount: Number }; connect() { this.updateCheckboxState(); } toggleCheckbox() { const selectedCheckboxes = this.checkboxTargets.filter((checkbox) => checkbox.checked); if (this.maxSelectionsCountValue === 0) { return; } else if (this.maxSelectionsCountValue> 1) { this.checkboxTargets.forEach((checkbox) => { if (selectedCheckboxes.length>= this.maxSelectionsCountValue && !checkbox.checked) { checkbox.disabled = true; checkbox.classList.add(this.disabledClass); } else { checkbox.disabled = false; checkbox.classList.remove(this.disabledClass); } }); } else { console.log('ERROR: It should be radio button'); } } }

AltStyle によって変換されたページ (->オリジナル) /