index.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { setAutoCompleteBehavior } from '#shared/components/Form/fields/FieldRecipient/features/setAutoCompleteBehavior.ts'
  3. import createInput from '#shared/form/core/createInput.ts'
  4. import addLink from '#shared/form/features/addLink.ts'
  5. import formUpdaterTrigger from '#shared/form/features/formUpdaterTrigger.ts'
  6. import FieldAutoCompleteInput from '../FieldAutoComplete/FieldAutoCompleteInput.vue'
  7. import { autoCompleteProps } from '../FieldAutoComplete/index.ts'
  8. import type { FormKitNode } from '@formkit/core'
  9. const setFilterProps = (node: FormKitNode) => {
  10. const { props } = node
  11. // Define validation of search input depending on the supplied user contact type.
  12. // Include helpful hint in the search input field.
  13. if (props.contact === 'phone') {
  14. props.filterInputPlaceholder = __('Search or enter phone number…')
  15. // Very rudimentary validator for the E.164 telephone number format, i.e. +499876543210.
  16. props.filterInputValidation = 'matches:/^\\+?[1-9]\\d+$/'
  17. } else {
  18. props.filterInputPlaceholder = __('Search or enter email address…')
  19. props.filterInputValidation = 'email'
  20. }
  21. }
  22. const fieldDefinition = createInput(
  23. FieldAutoCompleteInput,
  24. autoCompleteProps,
  25. {
  26. features: [
  27. addLink,
  28. setAutoCompleteBehavior,
  29. setFilterProps,
  30. formUpdaterTrigger(),
  31. ],
  32. },
  33. { addArrow: true },
  34. )
  35. export default {
  36. fieldType: 'recipient',
  37. definition: fieldDefinition,
  38. }