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

Version Path
ariadne_view_components-0.0.93.2 app/frontend/controllers/form_validity_controller.ts
ariadne_view_components-0.0.93.1 app/frontend/controllers/form_validity_controller.ts
ariadne_view_components-0.0.93 app/frontend/controllers/form_validity_controller.ts
ariadne_view_components-0.0.92 app/frontend/controllers/form_validity_controller.ts
ariadne_view_components-0.0.91 app/frontend/controllers/form_validity_controller.ts
ariadne_view_components-0.0.90 app/frontend/controllers/form_validity_controller.ts
ariadne_view_components-0.0.89.1 app/frontend/controllers/form_validity_controller.ts
ariadne_view_components-0.0.89 app/frontend/controllers/form_validity_controller.ts
ariadne_view_components-0.0.88 app/frontend/controllers/form_validity_controller.ts
ariadne_view_components-0.0.87 app/frontend/controllers/form_validity_controller.ts
ariadne_view_components-0.0.86.9 app/frontend/controllers/form_validity_controller.ts
ariadne_view_components-0.0.86.8 app/frontend/controllers/form_validity_controller.ts
ariadne_view_components-0.0.86.7 app/frontend/controllers/form_validity_controller.ts
ariadne_view_components-0.0.86.6 app/frontend/controllers/form_validity_controller.ts
ariadne_view_components-0.0.86.5 app/frontend/controllers/form_validity_controller.ts
ariadne_view_components-0.0.86.4 app/frontend/controllers/form_validity_controller.ts
ariadne_view_components-0.0.86.3 app/frontend/controllers/form_validity_controller.ts
ariadne_view_components-0.0.86.2 app/frontend/controllers/form_validity_controller.ts
ariadne_view_components-0.0.86.1 app/frontend/controllers/form_validity_controller.ts
ariadne_view_components-0.0.86 app/frontend/controllers/form_validity_controller.ts