index.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. import type { FormKitNode } from '@formkit/core'
  3. import createInput from '@shared/form/core/createInput'
  4. import addLink from '@shared/form/features/addLink'
  5. import FieldAutoCompleteInput from '../FieldAutoComplete/FieldAutoCompleteInput.vue'
  6. import { autoCompleteProps } from '../FieldAutoComplete'
  7. const setAutoCompleteBehavior = (node: FormKitNode) => {
  8. const { props } = node
  9. // Allow selection of unknown values, but only if they pass email validation.
  10. // Include helpful hint in the search input field.
  11. props.allowUnknownValues = true
  12. props.filterInputPlaceholder = __('Search or enter email address...')
  13. props.filterInputValidation = 'email'
  14. node.addProps(['gqlQuery'])
  15. props.gqlQuery = `
  16. query autocompleteSearchRecipient($query: String!, $limit: Int) {
  17. autocompleteSearchRecipient(query: $query, limit: $limit) {
  18. value
  19. label
  20. labelPlaceholder
  21. heading
  22. headingPlaceholder
  23. disabled
  24. icon
  25. }
  26. }
  27. `
  28. }
  29. const fieldDefinition = createInput(FieldAutoCompleteInput, autoCompleteProps, {
  30. features: [addLink, setAutoCompleteBehavior],
  31. })
  32. export default {
  33. fieldType: 'recipient',
  34. definition: fieldDefinition,
  35. }