Sha256: 5b6da2ddf0d9caf65eb975532bbd135f00bf6b5611f6badb1d61a9f4f2ebebc6
Contents?: true
Size: 800 Bytes
Versions: 26
Compression:
Stored size: 800 Bytes
Contents
import {controllerFactory} from '@utils/createController' import {useMutation} from 'stimulus-use' /** * Simple controller that sets `disabled` attribute on submit button * based on the basic validity of the form (HTML validation only). */ export default class FormValidity extends controllerFactory<HTMLFormElement>()({ targets: { button: HTMLButtonElement, form: HTMLFormElement, }, }) { private get form(): HTMLFormElement { return this.hasFormTarget ? this.formTarget : this.element } private runCheck() { this.buttonTarget.disabled = !this.form.checkValidity() } connect() { this.form.addEventListener('input', () => this.runCheck()) this.runCheck() useMutation(this, {childList: true, subtree: true}) } mutate() { this.runCheck() } }
Version data entries
26 entries across 26 versions & 1 rubygems