index.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import {
  3. color as inputColorDefinition,
  4. email as inputEmailDefinition,
  5. number as inputCNumberDefinition,
  6. tel as inputTelDefinition,
  7. text as inputTextDefinition,
  8. time as inputTimeDefinition,
  9. textInput,
  10. url as inputUrlDefinition,
  11. } from '@formkit/inputs'
  12. import initializeFieldDefinition from '#shared/form/core/initializeFieldDefinition.ts'
  13. import addLink from '#shared/form/features/addLink.ts'
  14. import addSubmitEvent from '#shared/form/features/addSubmitEvent.ts'
  15. import defaultEmptyValueString from '#shared/form/features/defaultEmptyValueString.ts'
  16. import formUpdaterTrigger from '#shared/form/features/formUpdaterTrigger.ts'
  17. import { setPopulatedOnWebkitAutofill } from '#shared/form/features/setPopulatedOnWebkitAutofill.ts'
  18. import type {
  19. FormFieldsTypeDefinition,
  20. FormFieldType,
  21. } from '#shared/types/form.ts'
  22. const inputFieldDefinitionList: FormFieldsTypeDefinition = {
  23. text: inputTextDefinition,
  24. color: inputColorDefinition,
  25. email: inputEmailDefinition,
  26. number: inputCNumberDefinition,
  27. tel: inputTelDefinition,
  28. time: inputTimeDefinition,
  29. url: inputUrlDefinition,
  30. }
  31. const inputFields: FormFieldType[] = []
  32. Object.keys(inputFieldDefinitionList).forEach((inputType) => {
  33. initializeFieldDefinition(
  34. inputFieldDefinitionList[inputType],
  35. {
  36. features: [
  37. addLink,
  38. addSubmitEvent,
  39. formUpdaterTrigger('delayed'),
  40. setPopulatedOnWebkitAutofill,
  41. defaultEmptyValueString,
  42. ],
  43. },
  44. { schema: textInput },
  45. )
  46. inputFields.push({
  47. fieldType: inputType,
  48. definition: inputFieldDefinitionList[inputType],
  49. })
  50. })
  51. export default inputFields