mirror of
https://github.com/zammad/zammad
synced 2026-05-24 09:48:36 +00:00
27 lines
830 B
TypeScript
27 lines
830 B
TypeScript
// Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/
|
|
|
|
import { onUnmounted } from 'vue'
|
|
|
|
import type { FormFieldContext } from '#shared/components/Form/types/field.ts'
|
|
|
|
import type { Ref } from 'vue'
|
|
|
|
// TODO maybe there is a better way to do this with FormKit?
|
|
export const useFormBlock = (context: Ref<FormFieldContext>, cb: (e: MouseEvent) => void) => {
|
|
const receipt = context.value.node.on('block-click', ({ payload }) => {
|
|
if (context.value.disabled) return
|
|
|
|
const target = payload.target as HTMLElement | null
|
|
|
|
// ignore link
|
|
if (!target || target.classList.contains('formkit-link')) return
|
|
if (target.querySelector('.formkit-link')) return
|
|
if (target.closest('.formkit-link')) return
|
|
|
|
cb(payload)
|
|
})
|
|
|
|
onUnmounted(() => {
|
|
context.value.node.off(receipt)
|
|
})
|
|
}
|