hideField.ts 596 B

12345678910111213141516171819202122232425
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import type { FormKitNode } from '@formkit/core'
  3. const hideField = (node: FormKitNode) => {
  4. node.addProps(['hidden'])
  5. node.on('created', () => {
  6. const { props } = node
  7. if (props.hidden) {
  8. props.outerClass = 'hidden'
  9. }
  10. node.on('prop:hidden', ({ payload }) => {
  11. if (payload) {
  12. props.outerClass = `${props.outerClass} hidden`
  13. } else if (props.outerClass) {
  14. props.outerClass = props.outerClass.replace('hidden', '')
  15. }
  16. })
  17. })
  18. }
  19. export default hideField