- Guard against empty awardTypeIds array in AwardRepository - Refactor Stimulus controller to use data-action attributes instead of imperative addEventListener (fixes duplicate listener issue) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
34 lines
972 B
JavaScript
34 lines
972 B
JavaScript
import { Controller } from '@hotwired/stimulus';
|
|
|
|
export default class extends Controller {
|
|
static targets = ['hintType', 'awardSection', 'allAwards', 'awardType'];
|
|
|
|
enforceMinOneChecked(event) {
|
|
const checked = this.hintTypeTargets.filter((e) => e.checked);
|
|
if (checked.length === 0) {
|
|
event.target.checked = true;
|
|
}
|
|
this.toggleAwardSection();
|
|
}
|
|
|
|
toggleAwardSection() {
|
|
const awardChecked = this.hintTypeTargets.find(
|
|
(el) => el.name === 'hint_award'
|
|
)?.checked;
|
|
|
|
this.awardSectionTarget.style.display = awardChecked ? '' : 'none';
|
|
}
|
|
|
|
toggleAllAwards() {
|
|
const checked = this.allAwardsTarget.checked;
|
|
this.awardTypeTargets.forEach((el) => {
|
|
el.checked = checked;
|
|
});
|
|
}
|
|
|
|
syncAllAwards() {
|
|
const allChecked = this.awardTypeTargets.every((el) => el.checked);
|
|
this.allAwardsTarget.checked = allChecked;
|
|
}
|
|
}
|