addBlurEvent.ts 514 B

1234567891011121314151617181920
  1. // Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. import type { FormKitNode } from '@formkit/core'
  3. const addBlurEvent = (node: FormKitNode) => {
  4. node.on('created', () => {
  5. if (!node.context) return
  6. const originalBlurHandler = node.context.handlers.blur as (
  7. e?: FocusEvent,
  8. ) => void
  9. node.context.handlers.blur = (event?: FocusEvent) => {
  10. node.emit('blur', node.context?.value)
  11. originalBlurHandler(event)
  12. }
  13. })
  14. }
  15. export default addBlurEvent