UNPKG

@stimulus-library/controllers

Version:

A library of useful controllers for Stimulus

33 lines (32 loc) 865 B
import { BaseController } from "@stimulus-library/utilities"; export class CheckboxDisableInputsController extends BaseController { connect() { this.toggle(); } toggle() { if (this.hasDisablerTarget && this.disablerTarget.checked) { this.disable(); } else { this.enable(); } } disable() { const shouldClear = this.hasClearValue && this.clearValue; this.disableTargets.forEach((el, _) => { if (shouldClear) { el.value = ""; } el.disabled = true; }); } enable() { this.disableTargets.forEach((el, _) => { el.disabled = false; }); } } CheckboxDisableInputsController.targets = ["disabler", "disable"]; CheckboxDisableInputsController.values = { clear: Boolean, };