addBlurEvent.ts 585 B

1234567891011121314151617181920212223
  1. // Copyright (C) 2012-2024 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. // if node was not destroyed
  12. if (node.context) {
  13. originalBlurHandler(event)
  14. }
  15. }
  16. })
  17. }
  18. export default addBlurEvent