input.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import type { FormFieldAdditionalProps } from '#shared/components/Form/types.ts'
  3. import type { FieldResolverModule } from '#shared/entities/object-attributes/types/resolver.ts'
  4. import FieldResolver from '../FieldResolver.ts'
  5. export class FieldResolverInput extends FieldResolver {
  6. fieldType = () => {
  7. switch (this.attributeConfig.type) {
  8. case 'password':
  9. return 'password'
  10. case 'tel':
  11. return 'tel'
  12. case 'email':
  13. return 'email'
  14. case 'url':
  15. return 'url'
  16. default:
  17. return 'text'
  18. }
  19. }
  20. public fieldTypeAttributes() {
  21. const props: FormFieldAdditionalProps = {
  22. maxlength: this.attributeConfig.maxlength,
  23. }
  24. const valiadtion = this.validation()
  25. if (valiadtion) {
  26. props.validation = valiadtion
  27. }
  28. return {
  29. props,
  30. }
  31. }
  32. private validation() {
  33. switch (this.attributeConfig.type) {
  34. case 'email':
  35. return 'email'
  36. case 'url':
  37. return 'url'
  38. default:
  39. return null
  40. }
  41. }
  42. }
  43. export default <FieldResolverModule>{
  44. type: 'input',
  45. resolver: FieldResolverInput,
  46. }