@ldquocc/dynamic-form 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (298) hide show
  1. package/ng-package.json +15 -0
  2. package/package.json +20 -31
  3. package/src/lib/dynamic-form.component.html +121 -0
  4. package/src/lib/dynamic-form.component.scss +7 -0
  5. package/src/lib/dynamic-form.component.spec.ts +21 -0
  6. package/src/lib/dynamic-form.component.ts +237 -0
  7. package/src/lib/dynamic-form.service.spec.ts +16 -0
  8. package/src/lib/dynamic-form.service.ts +9 -0
  9. package/src/lib/shared/base/base-select.component.ts +183 -0
  10. package/src/lib/shared/base/base-value-accessor.ts +192 -0
  11. package/{lib/shared/components/component.d.ts → src/lib/shared/components/component.ts} +34 -14
  12. package/src/lib/shared/components/d-form-testing/d-form-testing.component.html +197 -0
  13. package/src/lib/shared/components/d-form-testing/d-form-testing.component.less +12 -0
  14. package/src/lib/shared/components/d-form-testing/d-form-testing.component.spec.ts +22 -0
  15. package/src/lib/shared/components/d-form-testing/d-form-testing.component.ts +197 -0
  16. package/src/lib/shared/components/dynamic-field/dynamic-field.component.html +218 -0
  17. package/src/lib/shared/components/dynamic-field/dynamic-field.component.scss +28 -0
  18. package/src/lib/shared/components/dynamic-field/dynamic-field.component.spec.ts +21 -0
  19. package/src/lib/shared/components/dynamic-field/dynamic-field.component.ts +67 -0
  20. package/src/lib/shared/components/field-user-config/field-user-config.component.html +38 -0
  21. package/src/lib/shared/components/field-user-config/field-user-config.component.scss +29 -0
  22. package/src/lib/shared/components/field-user-config/field-user-config.component.ts +33 -0
  23. package/src/lib/shared/components/fields/components/suffix/suffix.component.html +42 -0
  24. package/src/lib/shared/components/fields/components/suffix/suffix.component.scss +3 -0
  25. package/src/lib/shared/components/fields/components/suffix/suffix.component.spec.ts +22 -0
  26. package/src/lib/shared/components/fields/components/suffix/suffix.component.ts +32 -0
  27. package/src/lib/shared/components/fields/date/date-picker/date-picker.component.html +20 -0
  28. package/src/lib/shared/components/fields/date/date-picker/date-picker.component.scss +5 -0
  29. package/src/lib/shared/components/fields/date/date-picker/date-picker.component.spec.ts +21 -0
  30. package/src/lib/shared/components/fields/date/date-picker/date-picker.component.ts +148 -0
  31. package/src/lib/shared/components/fields/date/date-range/date-range.component.html +33 -0
  32. package/src/lib/shared/components/fields/date/date-range/date-range.component.scss +22 -0
  33. package/src/lib/shared/components/fields/date/date-range/date-range.component.spec.ts +21 -0
  34. package/src/lib/shared/components/fields/date/date-range/date-range.component.ts +133 -0
  35. package/src/lib/shared/components/fields/input/input-formatted/input-formatted.component.html +31 -0
  36. package/src/lib/shared/components/fields/input/input-formatted/input-formatted.component.scss +3 -0
  37. package/src/lib/shared/components/fields/input/input-formatted/input-formatted.component.spec.ts +21 -0
  38. package/src/lib/shared/components/fields/input/input-formatted/input-formatted.component.ts +148 -0
  39. package/src/lib/shared/components/fields/input/input-password/input-password.component.html +18 -0
  40. package/src/lib/shared/components/fields/input/input-password/input-password.component.scss +0 -0
  41. package/src/lib/shared/components/fields/input/input-password/input-password.component.spec.ts +21 -0
  42. package/src/lib/shared/components/fields/input/input-password/input-password.component.ts +56 -0
  43. package/src/lib/shared/components/fields/input/input-text/input-text.component.html +73 -0
  44. package/src/lib/shared/components/fields/input/input-text/input-text.component.scss +0 -0
  45. package/src/lib/shared/components/fields/input/input-text/input-text.component.spec.ts +21 -0
  46. package/src/lib/shared/components/fields/input/input-text/input-text.component.ts +98 -0
  47. package/src/lib/shared/components/fields/select/multi-select/multi-select.component.html +73 -0
  48. package/src/lib/shared/components/fields/select/multi-select/multi-select.component.scss +21 -0
  49. package/src/lib/shared/components/fields/select/multi-select/multi-select.component.spec.ts +21 -0
  50. package/src/lib/shared/components/fields/select/multi-select/multi-select.component.ts +212 -0
  51. package/src/lib/shared/components/fields/select/single-select/single-select.component.html +55 -0
  52. package/src/lib/shared/components/fields/select/single-select/single-select.component.scss +1 -0
  53. package/src/lib/shared/components/fields/select/single-select/single-select.component.spec.ts +21 -0
  54. package/src/lib/shared/components/fields/select/single-select/single-select.component.ts +217 -0
  55. package/src/lib/shared/components/fields/select/single-select/sl.component.old.txt +337 -0
  56. package/src/lib/shared/components/fields/select/single-select/sl.component.old2.txt +340 -0
  57. package/src/lib/shared/components/fields/select/tree-select/tree-select.component.html +38 -0
  58. package/src/lib/shared/components/fields/select/tree-select/tree-select.component.scss +1 -0
  59. package/src/lib/shared/components/fields/select/tree-select/tree-select.component.spec.ts +21 -0
  60. package/src/lib/shared/components/fields/select/tree-select/tree-select.component.ts +401 -0
  61. package/src/lib/shared/components/fields/textarea/textarea.component.html +29 -0
  62. package/src/lib/shared/components/fields/textarea/textarea.component.scss +17 -0
  63. package/src/lib/shared/components/fields/textarea/textarea.component.spec.ts +21 -0
  64. package/src/lib/shared/components/fields/textarea/textarea.component.ts +76 -0
  65. package/src/lib/shared/components/fields/upload/avatar-upload/avatar-upload.component.html +30 -0
  66. package/src/lib/shared/components/fields/upload/avatar-upload/avatar-upload.component.scss +22 -0
  67. package/src/lib/shared/components/fields/upload/avatar-upload/avatar-upload.component.spec.ts +22 -0
  68. package/src/lib/shared/components/fields/upload/avatar-upload/avatar-upload.component.ts +217 -0
  69. package/src/lib/shared/components/fields/upload/multi-file-upload/multi-file-upload.component.html +101 -0
  70. package/src/lib/shared/components/fields/upload/multi-file-upload/multi-file-upload.component.scss +117 -0
  71. package/src/lib/shared/components/fields/upload/multi-file-upload/multi-file-upload.component.spec.ts +22 -0
  72. package/src/lib/shared/components/fields/upload/multi-file-upload/multi-file-upload.component.ts +480 -0
  73. package/src/lib/shared/components/fields/upload/multi-image-upload/multi-image-upload.component.html +82 -0
  74. package/src/lib/shared/components/fields/upload/multi-image-upload/multi-image-upload.component.less +80 -0
  75. package/src/lib/shared/components/fields/upload/multi-image-upload/multi-image-upload.component.spec.ts +22 -0
  76. package/src/lib/shared/components/fields/upload/multi-image-upload/multi-image-upload.component.ts +288 -0
  77. package/src/lib/shared/components/fields/upload/single-file-upload/single-file-upload.component.html +104 -0
  78. package/src/lib/shared/components/fields/upload/single-file-upload/single-file-upload.component.scss +37 -0
  79. package/src/lib/shared/components/fields/upload/single-file-upload/single-file-upload.component.spec.ts +21 -0
  80. package/src/lib/shared/components/fields/upload/single-file-upload/single-file-upload.component.ts +317 -0
  81. package/src/lib/shared/config/dynamic-form.config.ts +11 -0
  82. package/src/lib/shared/consts/common/common.const.ts +5 -0
  83. package/src/lib/shared/consts/common/field-dependency.const.ts +1 -0
  84. package/src/lib/shared/consts/common/file.const.ts +130 -0
  85. package/{lib/shared/consts/common/index.d.ts → src/lib/shared/consts/common/index.ts} +4 -4
  86. package/src/lib/shared/consts/common/sample-test.const.ts +1648 -0
  87. package/src/lib/shared/consts/common/standalone-import.const.ts +51 -0
  88. package/src/lib/shared/consts/controls/control.const.ts +11 -0
  89. package/{lib/shared/consts/controls/index.d.ts → src/lib/shared/consts/controls/index.ts} +1 -1
  90. package/src/lib/shared/consts/fields/date-field.const.ts +12 -0
  91. package/src/lib/shared/consts/fields/field.const.ts +23 -0
  92. package/{lib/shared/consts/fields/index.d.ts → src/lib/shared/consts/fields/index.ts} +5 -5
  93. package/src/lib/shared/consts/fields/input-field.const.ts +4 -0
  94. package/src/lib/shared/consts/fields/input-formatted-field.const.ts +35 -0
  95. package/src/lib/shared/consts/fields/radio-field.const.ts +31 -0
  96. package/src/lib/shared/consts/fields/select-field.const.ts +7 -0
  97. package/src/lib/shared/consts/fields/upload-field.const.ts +1 -0
  98. package/src/lib/shared/consts/validators/index.ts +0 -0
  99. package/src/lib/shared/consts/validators/pattern.const.ts +117 -0
  100. package/src/lib/shared/enums/common/component-ui.enum.ts +8 -0
  101. package/src/lib/shared/enums/common/field-dependency.enum.ts +10 -0
  102. package/src/lib/shared/enums/common/file-size-type.enum.ts +6 -0
  103. package/{lib/shared/enums/common/index.d.ts → src/lib/shared/enums/common/index.ts} +4 -4
  104. package/src/lib/shared/enums/common/output-value-type.enum.ts +22 -0
  105. package/src/lib/shared/enums/common/view-mode.enum.ts +4 -0
  106. package/src/lib/shared/enums/controls/control.enum.ts +12 -0
  107. package/{lib/shared/enums/controls/index.d.ts → src/lib/shared/enums/controls/index.ts} +1 -1
  108. package/src/lib/shared/enums/fields/date-field.enum.ts +4 -0
  109. package/src/lib/shared/enums/fields/field.enum.ts +21 -0
  110. package/{lib/shared/enums/fields/index.d.ts → src/lib/shared/enums/fields/index.ts} +6 -6
  111. package/src/lib/shared/enums/fields/input-field.enum.ts +6 -0
  112. package/src/lib/shared/enums/fields/input-formatted-field.enum.ts +6 -0
  113. package/src/lib/shared/enums/fields/select-field.enum.ts +4 -0
  114. package/src/lib/shared/enums/fields/upload-field.enum.ts +5 -0
  115. package/src/lib/shared/enums/form/dynamic-form.enum.ts +6 -0
  116. package/{lib/shared/enums/form/index.d.ts → src/lib/shared/enums/form/index.ts} +1 -1
  117. package/{lib/shared/enums/validators/index.d.ts → src/lib/shared/enums/validators/index.ts} +2 -2
  118. package/src/lib/shared/enums/validators/regex.enum.ts +47 -0
  119. package/src/lib/shared/enums/validators/validators.enum.ts +17 -0
  120. package/src/lib/shared/factories/auto-numeric-options.factory.ts +14 -0
  121. package/src/lib/shared/models/common/api-config.model.ts +7 -0
  122. package/src/lib/shared/models/common/api-response.model.ts +20 -0
  123. package/src/lib/shared/models/common/common.model.ts +39 -0
  124. package/src/lib/shared/models/common/field-dependency.model.ts +27 -0
  125. package/src/lib/shared/models/common/file-config.model.ts +22 -0
  126. package/{lib/shared/models/common/index.d.ts → src/lib/shared/models/common/index.ts} +7 -7
  127. package/src/lib/shared/models/common/obj-field.model.ts +68 -0
  128. package/src/lib/shared/models/common/object-storage.model.ts +15 -0
  129. package/{lib/shared/models/common/output-value-type.model.d.ts → src/lib/shared/models/common/output-value-type.model.ts} +4 -4
  130. package/src/lib/shared/models/common/table-models.ts +16 -0
  131. package/{lib/shared/models/common/view-mode.model.d.ts → src/lib/shared/models/common/view-mode.model.ts} +1 -1
  132. package/{lib/shared/models/controls/control.model.d.ts → src/lib/shared/models/controls/control.model.ts} +3 -2
  133. package/{lib/shared/models/controls/index.d.ts → src/lib/shared/models/controls/index.ts} +1 -1
  134. package/src/lib/shared/models/fields/date/base-date-field.model.ts +52 -0
  135. package/src/lib/shared/models/fields/date/date-picker-field.model.ts +43 -0
  136. package/src/lib/shared/models/fields/date/date-range-field.model.ts +52 -0
  137. package/{lib/shared/models/fields/date/index.d.ts → src/lib/shared/models/fields/date/index.ts} +3 -3
  138. package/src/lib/shared/models/fields/field-grid.model.ts +10 -0
  139. package/src/lib/shared/models/fields/field-group.model.ts +50 -0
  140. package/src/lib/shared/models/fields/field-user-config.model.ts +8 -0
  141. package/src/lib/shared/models/fields/field.model.ts +184 -0
  142. package/{lib/shared/models/fields/index.d.ts → src/lib/shared/models/fields/index.ts} +2 -2
  143. package/{lib/shared/models/fields/input/index.d.ts → src/lib/shared/models/fields/input/index.ts} +4 -4
  144. package/src/lib/shared/models/fields/input/input-field.model.ts +111 -0
  145. package/src/lib/shared/models/fields/input/input-formatted-field.model.ts +38 -0
  146. package/src/lib/shared/models/fields/input/input-password-field.model.ts +38 -0
  147. package/src/lib/shared/models/fields/input/input-text-field.model.ts +26 -0
  148. package/src/lib/shared/models/fields/radio/index.ts +0 -0
  149. package/src/lib/shared/models/fields/radio/radio-base-field.model.ts +84 -0
  150. package/src/lib/shared/models/fields/select/index.ts +0 -0
  151. package/src/lib/shared/models/fields/select/multi-select-field.model.ts +46 -0
  152. package/src/lib/shared/models/fields/select/select-base-field.model.ts +125 -0
  153. package/src/lib/shared/models/fields/select/single-select-field.model.ts +43 -0
  154. package/src/lib/shared/models/fields/select/tree-select-field.model.ts +44 -0
  155. package/src/lib/shared/models/fields/textarea/index.ts +0 -0
  156. package/src/lib/shared/models/fields/textarea/textarea-field.model.ts +97 -0
  157. package/src/lib/shared/models/fields/upload/avatar-upload-field.model.ts +33 -0
  158. package/src/lib/shared/models/fields/upload/base-upload-field.model.ts +105 -0
  159. package/{lib/shared/models/fields/upload/index.d.ts → src/lib/shared/models/fields/upload/index.ts} +5 -5
  160. package/src/lib/shared/models/fields/upload/multi-file-upload-field.model.ts +34 -0
  161. package/src/lib/shared/models/fields/upload/multi-image-upload-field.model.ts +42 -0
  162. package/src/lib/shared/models/fields/upload/single-file-upload-field.model.ts +33 -0
  163. package/{lib/shared/models/form/dynamic-form.model.d.ts → src/lib/shared/models/form/dynamic-form.model.ts} +1 -1
  164. package/{lib/shared/models/form/index.d.ts → src/lib/shared/models/form/index.ts} +1 -1
  165. package/src/lib/shared/models/validations/index.ts +1 -0
  166. package/src/lib/shared/models/validations/validations.model.ts +14 -0
  167. package/src/lib/shared/services/dynamic-form.service.spec.ts +16 -0
  168. package/src/lib/shared/services/dynamic-form.service.ts +251 -0
  169. package/src/lib/shared/services/field.service.spec.ts +16 -0
  170. package/src/lib/shared/services/field.service.ts +152 -0
  171. package/src/lib/shared/services/file.service.spec.ts +16 -0
  172. package/src/lib/shared/services/file.service.ts +53 -0
  173. package/src/lib/shared/services/form-config.service.ts +53 -0
  174. package/src/lib/shared/services/form-data.service.spec.ts +16 -0
  175. package/src/lib/shared/services/form-data.service.ts +114 -0
  176. package/src/lib/shared/services/form-utils.ts +52 -0
  177. package/src/lib/shared/services/suffix.service.spec.ts +16 -0
  178. package/src/lib/shared/services/suffix.service.ts +16 -0
  179. package/src/lib/shared/services/validation.service.spec.ts +16 -0
  180. package/src/lib/shared/services/validation.service.ts +38 -0
  181. package/src/lib/shared/utils/common/common.utils.ts +52 -0
  182. package/{lib/shared/utils/common/index.d.ts → src/lib/shared/utils/common/index.ts} +1 -1
  183. package/src/lib/shared/utils/date/date.utils.ts +129 -0
  184. package/{lib/shared/utils/date/index.d.ts → src/lib/shared/utils/date/index.ts} +1 -1
  185. package/src/lib/shared/utils/dynamic-field/dynamic-field.ts +0 -0
  186. package/src/lib/shared/utils/dynamic-field/index.ts +0 -0
  187. package/src/lib/shared/utils/dynamic-form/dynamic-form.ts +114 -0
  188. package/src/lib/shared/utils/dynamic-form/index.ts +0 -0
  189. package/src/lib/shared/utils/fields/fields.ts +78 -0
  190. package/{lib/shared/utils/fields/index.d.ts → src/lib/shared/utils/fields/index.ts} +1 -1
  191. package/src/lib/shared/utils/file/file.utils.ts +37 -0
  192. package/{lib/shared/utils/file/index.d.ts → src/lib/shared/utils/file/index.ts} +1 -1
  193. package/src/lib/shared/utils/validators/custom-validators.ts +158 -0
  194. package/src/lib/shared/utils/validators/default-error-message.ts +42 -0
  195. package/{lib/shared/utils/validators/index.d.ts → src/lib/shared/utils/validators/index.ts} +3 -3
  196. package/src/lib/shared/utils/validators/pattern.ts +26 -0
  197. package/{public-api.d.ts → src/public-api.ts} +68 -28
  198. package/tsconfig.lib.json +15 -0
  199. package/tsconfig.lib.prod.json +11 -0
  200. package/tsconfig.spec.json +15 -0
  201. package/fesm2022/ldquocc-dynamic-form.mjs +0 -4938
  202. package/fesm2022/ldquocc-dynamic-form.mjs.map +0 -1
  203. package/index.d.ts +0 -5
  204. package/lib/dynamic-form.component.d.ts +0 -67
  205. package/lib/shared/base/base-select.component.d.ts +0 -19
  206. package/lib/shared/base/base-value-accessor.d.ts +0 -69
  207. package/lib/shared/components/dynamic-field/dynamic-field.component.d.ts +0 -23
  208. package/lib/shared/components/field-user-config/field-user-config.component.d.ts +0 -10
  209. package/lib/shared/components/fields/components/suffix/suffix.component.d.ts +0 -12
  210. package/lib/shared/components/fields/date/date-picker/date-picker.component.d.ts +0 -17
  211. package/lib/shared/components/fields/date/date-range/date-range.component.d.ts +0 -17
  212. package/lib/shared/components/fields/input/input-formatted/input-formatted.component.d.ts +0 -20
  213. package/lib/shared/components/fields/input/input-password/input-password.component.d.ts +0 -12
  214. package/lib/shared/components/fields/input/input-text/input-text.component.d.ts +0 -14
  215. package/lib/shared/components/fields/select/multi-select/multi-select.component.d.ts +0 -21
  216. package/lib/shared/components/fields/select/single-select/single-select.component.d.ts +0 -21
  217. package/lib/shared/components/fields/select/tree-select/tree-select.component.d.ts +0 -28
  218. package/lib/shared/components/fields/textarea/textarea.component.d.ts +0 -14
  219. package/lib/shared/components/fields/upload/avatar-upload/avatar-upload.component.d.ts +0 -25
  220. package/lib/shared/components/fields/upload/multi-file-upload/multi-file-upload.component.d.ts +0 -76
  221. package/lib/shared/components/fields/upload/multi-image-upload/multi-image-upload.component.d.ts +0 -27
  222. package/lib/shared/components/fields/upload/single-file-upload/single-file-upload.component.d.ts +0 -29
  223. package/lib/shared/config/dynamic-form.config.d.ts +0 -9
  224. package/lib/shared/consts/common/common.const.d.ts +0 -5
  225. package/lib/shared/consts/common/field-dependency.const.d.ts +0 -1
  226. package/lib/shared/consts/common/file.const.d.ts +0 -148
  227. package/lib/shared/consts/common/standalone-import.const.d.ts +0 -7
  228. package/lib/shared/consts/controls/control.const.d.ts +0 -1
  229. package/lib/shared/consts/fields/date-field.const.d.ts +0 -7
  230. package/lib/shared/consts/fields/field.const.d.ts +0 -4
  231. package/lib/shared/consts/fields/input-field.const.d.ts +0 -4
  232. package/lib/shared/consts/fields/input-formatted-field.const.d.ts +0 -4
  233. package/lib/shared/consts/fields/radio-field.const.d.ts +0 -10
  234. package/lib/shared/consts/fields/select-field.const.d.ts +0 -6
  235. package/lib/shared/consts/fields/upload-field.const.d.ts +0 -1
  236. package/lib/shared/consts/validators/pattern.const.d.ts +0 -2
  237. package/lib/shared/enums/common/field-dependency.enum.d.ts +0 -9
  238. package/lib/shared/enums/common/file-size-type.enum.d.ts +0 -6
  239. package/lib/shared/enums/common/output-value-type.enum.d.ts +0 -19
  240. package/lib/shared/enums/common/view-mode.enum.d.ts +0 -4
  241. package/lib/shared/enums/controls/control.enum.d.ts +0 -11
  242. package/lib/shared/enums/fields/date-field.enum.d.ts +0 -4
  243. package/lib/shared/enums/fields/field.enum.d.ts +0 -20
  244. package/lib/shared/enums/fields/input-field.enum.d.ts +0 -6
  245. package/lib/shared/enums/fields/input-formatted-field.enum.d.ts +0 -6
  246. package/lib/shared/enums/fields/select-field.enum.d.ts +0 -4
  247. package/lib/shared/enums/fields/upload-field.enum.d.ts +0 -5
  248. package/lib/shared/enums/form/dynamic-form.enum.d.ts +0 -6
  249. package/lib/shared/enums/validators/regex.enum.d.ts +0 -38
  250. package/lib/shared/enums/validators/validators.enum.d.ts +0 -14
  251. package/lib/shared/factories/auto-numeric-options.factory.d.ts +0 -5
  252. package/lib/shared/models/common/api-config.model.d.ts +0 -4
  253. package/lib/shared/models/common/api-response.model.d.ts +0 -19
  254. package/lib/shared/models/common/common.model.d.ts +0 -29
  255. package/lib/shared/models/common/field-dependency.model.d.ts +0 -16
  256. package/lib/shared/models/common/file-config.model.d.ts +0 -11
  257. package/lib/shared/models/common/obj-field.model.d.ts +0 -59
  258. package/lib/shared/models/common/object-storage.model.d.ts +0 -15
  259. package/lib/shared/models/common/table-models.d.ts +0 -15
  260. package/lib/shared/models/fields/date/base-date-field.model.d.ts +0 -19
  261. package/lib/shared/models/fields/date/date-picker-field.model.d.ts +0 -12
  262. package/lib/shared/models/fields/date/date-range-field.model.d.ts +0 -12
  263. package/lib/shared/models/fields/field-grid.model.d.ts +0 -9
  264. package/lib/shared/models/fields/field-group.model.d.ts +0 -21
  265. package/lib/shared/models/fields/field-user-config.model.d.ts +0 -3
  266. package/lib/shared/models/fields/field.model.d.ts +0 -57
  267. package/lib/shared/models/fields/input/input-field.model.d.ts +0 -31
  268. package/lib/shared/models/fields/input/input-formatted-field.model.d.ts +0 -13
  269. package/lib/shared/models/fields/input/input-password-field.model.d.ts +0 -11
  270. package/lib/shared/models/fields/input/input-text-field.model.d.ts +0 -9
  271. package/lib/shared/models/fields/radio/radio-base-field.model.d.ts +0 -26
  272. package/lib/shared/models/fields/select/multi-select-field.model.d.ts +0 -11
  273. package/lib/shared/models/fields/select/select-base-field.model.d.ts +0 -40
  274. package/lib/shared/models/fields/select/single-select-field.model.d.ts +0 -9
  275. package/lib/shared/models/fields/select/tree-select-field.model.d.ts +0 -10
  276. package/lib/shared/models/fields/textarea/textarea-field.model.d.ts +0 -20
  277. package/lib/shared/models/fields/upload/avatar-upload-field.model.d.ts +0 -9
  278. package/lib/shared/models/fields/upload/base-upload-field.model.d.ts +0 -25
  279. package/lib/shared/models/fields/upload/multi-file-upload-field.model.d.ts +0 -10
  280. package/lib/shared/models/fields/upload/multi-image-upload-field.model.d.ts +0 -12
  281. package/lib/shared/models/fields/upload/single-file-upload-field.model.d.ts +0 -11
  282. package/lib/shared/services/dynamic-form.service.d.ts +0 -48
  283. package/lib/shared/services/field.service.d.ts +0 -41
  284. package/lib/shared/services/file.service.d.ts +0 -20
  285. package/lib/shared/services/form-config.service.d.ts +0 -10
  286. package/lib/shared/services/form-data.service.d.ts +0 -53
  287. package/lib/shared/services/form-utils.d.ts +0 -5
  288. package/lib/shared/services/suffix.service.d.ts +0 -12
  289. package/lib/shared/services/validation.service.d.ts +0 -10
  290. package/lib/shared/utils/common/common.utils.d.ts +0 -7
  291. package/lib/shared/utils/date/date.utils.d.ts +0 -6
  292. package/lib/shared/utils/dynamic-form/dynamic-form.d.ts +0 -11
  293. package/lib/shared/utils/fields/fields.d.ts +0 -20
  294. package/lib/shared/utils/file/file.utils.d.ts +0 -4
  295. package/lib/shared/utils/validators/custom-validators.d.ts +0 -11
  296. package/lib/shared/utils/validators/default-error-message.d.ts +0 -6
  297. package/lib/shared/utils/validators/pattern.d.ts +0 -4
  298. /package/{styles → src/lib/shared/styles}/_common-form.scss +0 -0
@@ -0,0 +1,111 @@
1
+ import { FormControl, ValidatorFn, Validators } from '@angular/forms';
2
+ import { INPUT_FIELD_TYPES } from '../../../consts/fields/input-field.const';
3
+ import { BaseField } from '../field.model';
4
+ import { noLeadingSpaceValidator } from '../../../utils/validators/custom-validators';
5
+ import { resolvePattern } from '../../../utils/validators/pattern';
6
+ import { CommonValidaterEnum, CustomValidaterEnum } from '../../../enums/validators';
7
+ import {
8
+ getDefaultMaxLengthErrorMessage,
9
+ getDefaultMinLengthErrorMessage,
10
+ getDefaultPatternErrorMessage,
11
+ getLeadingSpaceErrorMessage,
12
+ } from '../../../utils/validators';
13
+ import { ControlTypeEnum } from '../../../enums/controls';
14
+ import { Suffix } from '../../common/common.model';
15
+
16
+ /**
17
+ * typeof FIELD_TYPES[number] có nghĩa là:
18
+ - INPUT_FIELD_TYPES là readonly ['text','email','password','number']
19
+ - INPUT_FIELD_TYPES[number] = INPUT_FIELD_TYPES[0] | INPUT_FIELD_TYPES[1] | ... = 'text' | 'email' | ...
20
+ => FieldType = 'input' | 'select' | 'checkbox'
21
+ */
22
+ export type InputFieldType = (typeof INPUT_FIELD_TYPES)[number];
23
+
24
+ const DEFAULT_INPUT_VALUE = '';
25
+
26
+ /**
27
+ * Interface base chung cho Các dạng Input Field.
28
+ */
29
+ export abstract class InputBaseField extends BaseField<string> {
30
+ suffixes: Suffix[];
31
+
32
+ /**
33
+ * Props validation chung cho các dạng Input.
34
+ */
35
+ // Độ dài tối thiểu của chuỗi nhập vào.
36
+ minLength?: number;
37
+ // Độ dài tối đa của chuỗi nhập vào.
38
+ maxLength?: number;
39
+ // Theo mẫu regex hoặc đối tượng RegExr
40
+ pattern?: string | RegExp;
41
+
42
+ isCurrency: boolean;
43
+
44
+ constructor(init: Partial<InputBaseField>) {
45
+ super(init);
46
+
47
+ /**
48
+ * Gán giá trị cho các props cần giá trị mặc định ở Input.
49
+ */
50
+ this.controlType = ControlTypeEnum.Input;
51
+ this.value = DEFAULT_INPUT_VALUE;
52
+ this.initialValue = DEFAULT_INPUT_VALUE;
53
+ this.suffixes = [];
54
+ this.isCurrency = false;
55
+
56
+ Object.assign(this, init);
57
+ }
58
+
59
+ // Mảng ValidatorFn các validation chung được hỗ trợ sẵn bởi Reactive form của angular cho Input.
60
+ protected getInputCommonValidators(): ValidatorFn[] {
61
+ const validators = this.getCommonValidators();
62
+
63
+ if (this.minLength) validators.push(Validators.minLength(this.minLength));
64
+ if (this.maxLength) validators.push(Validators.maxLength(this.maxLength));
65
+ if (this.pattern) {
66
+ const resolvePatternResult = resolvePattern(this.pattern);
67
+ if (resolvePatternResult?.type !== 'unknown')
68
+ validators.push(Validators.pattern(resolvePatternResult.value));
69
+ }
70
+
71
+ return validators;
72
+ }
73
+
74
+ // Mảng ValidatorFn các custom validation có thể dùng cho Input.
75
+ protected getInputCustomValidators(): ValidatorFn[] {
76
+ const validators = this.getCustomValidators();
77
+
78
+ validators.push(noLeadingSpaceValidator());
79
+
80
+ return validators;
81
+ }
82
+
83
+ // Tạo Form Control cho Input Field.
84
+ override toFormControl(): FormControl {
85
+ const commonValidators = this.getInputCommonValidators();
86
+ const customValidators = this.getInputCustomValidators();
87
+ return new FormControl(this.value ?? '', [...commonValidators, ...customValidators]);
88
+ }
89
+
90
+ // Giá trị mặc định.
91
+ override getDefaultValue(): string {
92
+ return DEFAULT_INPUT_VALUE;
93
+ }
94
+
95
+ override toFormValue(modelValue: unknown): string {
96
+ return String(modelValue);
97
+ }
98
+
99
+ override getErrorMessage(errorKey: string, errorValue: any, allFields: BaseField<any>[]): string {
100
+ if (errorKey === CommonValidaterEnum.Pattern) {
101
+ if (this.pattern) return getDefaultPatternErrorMessage(this.label, this.pattern);
102
+ }
103
+ if (errorKey === CommonValidaterEnum.MinLength)
104
+ return getDefaultMinLengthErrorMessage(this.label, errorValue);
105
+ if (errorKey === CommonValidaterEnum.MaxLength)
106
+ return getDefaultMaxLengthErrorMessage(this.label, errorValue);
107
+ if (errorKey === CustomValidaterEnum.LeadingSpace)
108
+ return getLeadingSpaceErrorMessage(this.label);
109
+ return super.getErrorMessage(errorKey, errorValue, allFields);
110
+ }
111
+ }
@@ -0,0 +1,38 @@
1
+ import { FormControl } from "@angular/forms";
2
+ import { FieldTypeEnum } from "../../../enums/fields";
3
+ import { InputBaseField } from "./input-field.model";
4
+ import { NumericPreset } from "../../../enums/fields/input-formatted-field.enum";
5
+ import AutoNumeric from "@zeedhi/autonumeric";
6
+
7
+ /**
8
+ * Interface của Input Field dạng format.
9
+ */
10
+ export class InputFormattedField extends InputBaseField {
11
+ // Kiểu định dạng số.
12
+ format: NumericPreset;
13
+
14
+ // Option cho autoNumeric. Có thê custom với dạng format là custom và truyền options từ ngoài vào.
15
+ autoNumericOptions?: Partial<AutoNumeric.Options>;
16
+
17
+ constructor(init: Partial<InputFormattedField>) {
18
+ super(init);
19
+
20
+ /**
21
+ * Gán giá trị cho các props cần giá trị mặc định ở InputFormatted.
22
+ */
23
+ this.type = FieldTypeEnum.InputFormatted;
24
+ this.format = NumericPreset.Integer;
25
+
26
+ Object.assign(this, init);
27
+ }
28
+
29
+ // Tạo Form Control cho Input Formatted Field.
30
+ override toFormControl(): FormControl {
31
+ const commonValidators = this.getInputCommonValidators();
32
+ const customValidators = this.getInputCustomValidators();
33
+ return new FormControl(this.value ?? "", [
34
+ ...commonValidators,
35
+ ...customValidators,
36
+ ]);
37
+ }
38
+ }
@@ -0,0 +1,38 @@
1
+ import { FormControl, ValidatorFn } from '@angular/forms';
2
+ import { FieldTypeEnum, InputFieldTypeEnum } from '../../../enums/fields';
3
+ import { InputBaseField } from './input-field.model';
4
+
5
+ /**
6
+ * Interface của Input Field type là Password.
7
+ */
8
+ export class InputPasswordField extends InputBaseField {
9
+ constructor(init: Partial<InputPasswordField>) {
10
+ super(init);
11
+
12
+ /**
13
+ * Gán giá trị cho các props cần giá trị mặc định ở Input Password.
14
+ */
15
+ this.type = FieldTypeEnum.InputPassword;
16
+
17
+ Object.assign(this, init);
18
+ }
19
+
20
+ // Mảng ValidatorFn các validation chung được hỗ trợ sẵn bởi Reactive form của angular cho Input Password.
21
+ protected getInputPasswordCommonValidators(): ValidatorFn[] {
22
+ const validators = this.getInputCommonValidators();
23
+ return validators;
24
+ }
25
+
26
+ // Mảng ValidatorFn các validation chung được hỗ trợ sẵn bởi angular cho Input Password.
27
+ protected getInputPasswordCustomValidators(): ValidatorFn[] {
28
+ const validators = this.getInputCustomValidators();
29
+ return validators;
30
+ }
31
+
32
+ // Tạo Form Control cho Input Password Field.
33
+ override toFormControl(): FormControl {
34
+ const commonValidators = this.getInputPasswordCommonValidators();
35
+ const customValidators = this.getInputPasswordCustomValidators();
36
+ return new FormControl(this.value ?? '', [...commonValidators, ...customValidators]);
37
+ }
38
+ }
@@ -0,0 +1,26 @@
1
+ import { FormControl } from '@angular/forms';
2
+ import { FieldTypeEnum } from '../../../enums/fields';
3
+ import { InputBaseField } from './input-field.model';
4
+
5
+ /**
6
+ * Interface của Input Field type là Text.
7
+ */
8
+ export class InputTextField extends InputBaseField {
9
+ constructor(init: Partial<InputTextField>) {
10
+ super(init);
11
+
12
+ /**
13
+ * Gán giá trị cho các props cần giá trị mặc định ở Input Text.
14
+ */
15
+ this.type = FieldTypeEnum.InputText;
16
+
17
+ Object.assign(this, init);
18
+ }
19
+
20
+ // Tạo Form Control cho Input Text Field.
21
+ override toFormControl(): FormControl {
22
+ const commonValidators = this.getInputCommonValidators();
23
+ const customValidators = this.getInputCustomValidators();
24
+ return new FormControl(this.value ?? '', [...commonValidators, ...customValidators]);
25
+ }
26
+ }
File without changes
@@ -0,0 +1,84 @@
1
+ import { FormControl, ValidatorFn } from '@angular/forms';
2
+ import {
3
+ DEFAULT_BIND_LABEL,
4
+ DEFAULT_BIND_VALUE,
5
+ SELECT_FIELD_TYPES,
6
+ } from '../../../consts/fields/select-field.const';
7
+ import { BaseField } from '../field.model';
8
+ import { ApiConfig, FieldDependency } from '../../common';
9
+ import { SelectOutputValueType } from '../../common/output-value-type.model';
10
+ import { SelectOutputValueTypeEnum } from '../../../enums/common';
11
+ import { ControlTypeEnum } from '../../../enums/controls';
12
+ import { FieldTypeEnum } from '../../../enums/fields';
13
+ import { RADIO_FIELD_TYPES } from '../../../consts/fields/radio-field.const';
14
+
15
+ export type RadioFieldType = (typeof RADIO_FIELD_TYPES)[number];
16
+
17
+ /**
18
+ * Interface base chung cho Các dạng Radio.
19
+ */
20
+ export abstract class RadioBaseField<K, TOptions = Record<string, unknown>> extends BaseField<K> {
21
+ // Key lấy ra nhãn hiển thị ở options.
22
+ bindLabel!: string;
23
+
24
+ // Key lấy ra giá trị ngầm ở options.
25
+ bindValue!: string;
26
+
27
+ // Mảng options cho việc lựa chọn được truyền tĩnh từ config.
28
+ options?: TOptions[];
29
+
30
+ // Cấu hình api nếu danh sách select dựa vào việc gọi api GET. Ưu tiên hơn options tĩnh truyền vào từ config.
31
+ apiConfig?: ApiConfig;
32
+
33
+ // Phụ thuộc vào một giá trị từ bất kỳ dạng field nào khác: Select, Input,...
34
+ dependsOn?: FieldDependency[];
35
+
36
+ // Biến đổi hiển thị option label từ option của options.
37
+ transformLabel?: (option: TOptions) => string;
38
+
39
+ /**
40
+ * Props validation chung cho các dạng Radio.
41
+ */
42
+ // ................. Chưa có .................
43
+
44
+ constructor(init: Partial<RadioBaseField<K, TOptions>>) {
45
+ super(init);
46
+
47
+ /**
48
+ * Gán giá trị cho các props cần giá trị mặc định ở Radio.
49
+ */
50
+ this.controlType = ControlTypeEnum.Radio;
51
+ this.bindLabel = DEFAULT_BIND_LABEL;
52
+ this.bindValue = DEFAULT_BIND_VALUE;
53
+ this.dependsOn = [];
54
+
55
+ Object.assign(this, init);
56
+ }
57
+
58
+ // Mảng ValidatorFn các validation chung được hỗ trợ sẵn bởi Reactive form của angular cho Radio.
59
+ protected getCommonSelectValidators(): ValidatorFn[] {
60
+ const validators = this.getCommonValidators();
61
+ return validators;
62
+ }
63
+
64
+ // Mảng ValidatorFn các custom validation có thể dùng cho Radio.
65
+ protected getCustomSelectValidators(): ValidatorFn[] {
66
+ const validators = this.getCustomValidators();
67
+ return validators;
68
+ }
69
+
70
+ // Tạo Form Control cho Input Field.
71
+ override toFormControl(): FormControl {
72
+ const commonValidators = this.getCommonSelectValidators();
73
+ const customValidators = this.getCustomSelectValidators();
74
+ return new FormControl(this.value ?? '', [...commonValidators, ...customValidators]);
75
+ }
76
+
77
+ abstract override getDefaultValue(): K;
78
+
79
+ abstract override toFormValue(modelValue: K): K;
80
+
81
+ override getErrorMessage(errorKey: string, errorValue: any, allFields: BaseField<any>[]): string {
82
+ return super.getErrorMessage(errorKey, errorValue, allFields);
83
+ }
84
+ }
File without changes
@@ -0,0 +1,46 @@
1
+ import { FieldTypeEnum } from '../../../enums/fields';
2
+ import { SelectBaseField } from './select-base-field.model';
3
+
4
+ const DEFAULT_MULTI_SELECT_VALUE: string[] = [];
5
+
6
+ /**
7
+ * Interface của Select Field type là dạng Multi.
8
+ */
9
+ export class MultiSelectField extends SelectBaseField<string[] | Record<string, unknown>[]> {
10
+ // Số lựa chọn (option) sẽ được hiển thị khi người dùng chọn nhiều.
11
+ maxTagCount?: number;
12
+ maxMultipleCount?: number;
13
+
14
+ constructor(init: Partial<MultiSelectField>) {
15
+ super(init);
16
+
17
+ /**
18
+ * Gán giá trị cho các props cần giá trị mặc định ở Multi Select.
19
+ */
20
+ this.type = FieldTypeEnum.MultiSelect;
21
+ this.value = DEFAULT_MULTI_SELECT_VALUE;
22
+ this.initialValue = DEFAULT_MULTI_SELECT_VALUE;
23
+ this.maxTagCount = 53;
24
+ this.maxMultipleCount = Infinity;
25
+
26
+ Object.assign(this, init);
27
+ }
28
+
29
+ override getDefaultValue(): string[] | Record<string, unknown>[] {
30
+ return DEFAULT_MULTI_SELECT_VALUE;
31
+ }
32
+
33
+ override toFormValue(modelValue: unknown): string[] | Record<string, unknown>[] {
34
+ const value = modelValue as string[] | Record<string, unknown>[];
35
+
36
+ const optionsValue = value!.map((val: string | number | Record<string, unknown>) => {
37
+ if (typeof val === 'object') {
38
+ let transformVal = (val?.[this.bindValue] as string) ?? '';
39
+ return transformVal;
40
+ }
41
+ return val as string;
42
+ });
43
+
44
+ return optionsValue;
45
+ }
46
+ }
@@ -0,0 +1,125 @@
1
+ import { FormControl, ValidatorFn } from "@angular/forms";
2
+ import {
3
+ DEFAULT_BIND_LABEL,
4
+ DEFAULT_BIND_VALUE,
5
+ SELECT_FIELD_TYPES,
6
+ } from "../../../consts/fields/select-field.const";
7
+ import { BaseField } from "../field.model";
8
+ import { ApiConfig, FieldDependency, FieldDependencyType } from "../../common";
9
+ import { SelectOutputValueType } from "../../common/output-value-type.model";
10
+ import {
11
+ DependTypeEnum,
12
+ SelectOutputValueTypeEnum,
13
+ } from "../../../enums/common";
14
+ import { ControlTypeEnum } from "../../../enums/controls";
15
+ import { Suffix } from "../../common/common.model";
16
+
17
+ export type SelectFieldType = (typeof SELECT_FIELD_TYPES)[number];
18
+
19
+ /**
20
+ * Interface base chung cho Các dạng Input Field.
21
+ */
22
+ export abstract class SelectBaseField<K> extends BaseField<K> {
23
+ // Key lấy ra nhãn hiển thị ở options.
24
+ bindLabel!: string;
25
+
26
+ // Key lấy ra giá trị ngầm ở options.
27
+ bindValue!: string;
28
+
29
+ // Dữ liệu sẽ gửi từ form khi submit.
30
+ outputAs!: SelectOutputValueType;
31
+
32
+ matchSelectWidth: boolean;
33
+
34
+ // Mảng options cho việc lựa chọn được truyền tĩnh từ config.
35
+ options: Record<string, unknown>[];
36
+
37
+ // Luôn chèn vào vị trí 0
38
+ optionsToPrepend: Record<string, unknown>[];
39
+
40
+ // Luôn chèn vào vị trí cuối
41
+ optionsToAppend: Record<string, unknown>[];
42
+
43
+ exceptOptions: Record<string, unknown>[];
44
+
45
+ // Phụ thuộc vào một giá trị từ bất kỳ dạng field nào khác: Select, Input,...
46
+ dependsOn: FieldDependency[];
47
+
48
+ // Cấu hình api nếu danh sách select dựa vào việc gọi api GET. Ưu tiên hơn options tĩnh truyền vào từ config.
49
+ apiConfig?: ApiConfig;
50
+
51
+ /**
52
+ * dependType:
53
+ * - 'all' → cần tất cả field cha có giá trị mới gọi API
54
+ * - 'any' → chỉ cần 1 field cha có giá trị cũng gọi API theo từng cha
55
+ */
56
+
57
+ dependType: FieldDependencyType;
58
+
59
+ // Biến đổi hiển thị option label từ option của options.
60
+ transformLabel?: (option: Record<string, unknown>) => string;
61
+
62
+ // Các nút nằm ở hậu tố (bên phải control).
63
+ suffixes: Suffix[];
64
+
65
+ /**
66
+ * Props validation chung cho các dạng Select.
67
+ */
68
+ // ................. Chưa có .................
69
+
70
+ constructor(init: Partial<SelectBaseField<K>>) {
71
+ super(init);
72
+
73
+ /**
74
+ * Gán giá trị cho các props cần giá trị mặc định ở Select.
75
+ */
76
+ this.controlType = ControlTypeEnum.Select;
77
+ this.bindLabel = DEFAULT_BIND_LABEL;
78
+ this.bindValue = DEFAULT_BIND_VALUE;
79
+ this.matchSelectWidth = true;
80
+ this.outputAs = SelectOutputValueTypeEnum.Object;
81
+ this.dependsOn = [];
82
+ this.dependType = DependTypeEnum.All;
83
+ this.suffixes = [];
84
+ this.optionsToPrepend = [];
85
+ this.optionsToAppend = [];
86
+ this.options = [];
87
+ this.exceptOptions = [];
88
+
89
+ Object.assign(this, init);
90
+ }
91
+
92
+ // Mảng ValidatorFn các validation chung được hỗ trợ sẵn bởi Reactive form của angular cho Select.
93
+ protected getCommonSelectValidators(): ValidatorFn[] {
94
+ const validators = this.getCommonValidators();
95
+ return validators;
96
+ }
97
+
98
+ // Mảng ValidatorFn các custom validation có thể dùng cho Select.
99
+ protected getCustomSelectValidators(): ValidatorFn[] {
100
+ const validators = this.getCustomValidators();
101
+ return validators;
102
+ }
103
+
104
+ // Tạo Form Control cho Input Field.
105
+ override toFormControl(): FormControl {
106
+ const commonValidators = this.getCommonSelectValidators();
107
+ const customValidators = this.getCustomSelectValidators();
108
+ return new FormControl(this.value ?? "", [
109
+ ...commonValidators,
110
+ ...customValidators,
111
+ ]);
112
+ }
113
+
114
+ abstract override getDefaultValue(): K;
115
+
116
+ abstract override toFormValue(modelValue: unknown): K;
117
+
118
+ override getErrorMessage(
119
+ errorKey: string,
120
+ errorValue: any,
121
+ allFields: BaseField<any>[],
122
+ ): string {
123
+ return super.getErrorMessage(errorKey, errorValue, allFields);
124
+ }
125
+ }
@@ -0,0 +1,43 @@
1
+ import { FieldTypeEnum } from '../../../enums/fields';
2
+ import { SelectBaseField } from './select-base-field.model';
3
+
4
+ const DEFAULT_SINGLE_SELECT_VALUE = null;
5
+
6
+ /**
7
+ * Interface của Select Field type là dạng Single.
8
+ */
9
+ export class SingleSelectField extends SelectBaseField<string | Record<string, unknown> | null> {
10
+ constructor(init: Partial<SingleSelectField>) {
11
+ super(init);
12
+
13
+ /**
14
+ * Gán giá trị cho các props cần giá trị mặc định ở Single Select.
15
+ */
16
+ this.type = FieldTypeEnum.SingleSelect;
17
+ this.value = DEFAULT_SINGLE_SELECT_VALUE;
18
+ this.initialValue = DEFAULT_SINGLE_SELECT_VALUE;
19
+
20
+ Object.assign(this, init);
21
+ }
22
+
23
+ override getDefaultValue(): string | Record<string, unknown> | null {
24
+ return DEFAULT_SINGLE_SELECT_VALUE;
25
+ }
26
+
27
+ override toFormValue(modelValue: unknown): string | Record<string, unknown> | null {
28
+ if (!modelValue) return null;
29
+ const value = modelValue as string | Record<string, unknown>;
30
+
31
+ if (typeof value === 'object') {
32
+ const valueFromObj = value?.[this.bindValue];
33
+ const typeOfValueFromObj = typeof valueFromObj;
34
+ if (typeOfValueFromObj !== 'object') return String(valueFromObj);
35
+ else {
36
+ console.warn('Từ bindValue nhưng đối tượng vẫn là dạng object');
37
+ return '';
38
+ }
39
+ }
40
+
41
+ return String(value);
42
+ }
43
+ }
@@ -0,0 +1,44 @@
1
+ import { FieldTypeEnum } from '../../../enums/fields';
2
+ import { SelectBaseField } from './select-base-field.model';
3
+
4
+ const DEFAULT_TREE_SELECT_VALUE = null;
5
+
6
+ /**
7
+ * Interface của Select Field type là dạng Single.
8
+ */
9
+ export class TreeSelectField extends SelectBaseField<string | Record<string, unknown> | null> {
10
+ groupBy?: string;
11
+ constructor(init: Partial<TreeSelectField>) {
12
+ super(init);
13
+
14
+ /**
15
+ * Gán giá trị cho các props cần giá trị mặc định ở Single Select.
16
+ */
17
+ this.type = FieldTypeEnum.TreeSelect;
18
+ this.value = DEFAULT_TREE_SELECT_VALUE;
19
+ this.initialValue = DEFAULT_TREE_SELECT_VALUE;
20
+
21
+ Object.assign(this, init);
22
+ }
23
+
24
+ override getDefaultValue(): string | Record<string, unknown> | null {
25
+ return DEFAULT_TREE_SELECT_VALUE;
26
+ }
27
+
28
+ override toFormValue(modelValue: unknown): string | Record<string, unknown> | null {
29
+ if (!modelValue) return null;
30
+ const value = modelValue as string | Record<string, unknown>;
31
+
32
+ if (typeof value === 'object') {
33
+ const valueFromObj = value?.[this.bindValue];
34
+ const typeOfValueFromObj = typeof valueFromObj;
35
+ if (typeOfValueFromObj !== 'object') return String(valueFromObj);
36
+ else {
37
+ console.warn('Từ bindValue nhưng đối tượng vẫn là dạng object');
38
+ return '';
39
+ }
40
+ }
41
+
42
+ return String(value);
43
+ }
44
+ }
File without changes
@@ -0,0 +1,97 @@
1
+ import { FormControl, ValidatorFn, Validators } from '@angular/forms';
2
+ import { FieldTypeEnum } from '../../../enums/fields';
3
+ import { BaseField } from '../field.model';
4
+ import {
5
+ getDefaultMaxLengthErrorMessage,
6
+ getDefaultMinLengthErrorMessage,
7
+ getDefaultPatternErrorMessage,
8
+ getLeadingSpaceErrorMessage,
9
+ noLeadingSpaceValidator,
10
+ resolvePattern,
11
+ } from '../../../utils/validators';
12
+ import { CommonValidaterEnum, CustomValidaterEnum } from '../../../enums/validators';
13
+ import { ControlTypeEnum } from '../../../enums/controls';
14
+
15
+ const DEFAULT_TEXTAREA_VALUE = '';
16
+
17
+ /**
18
+ * Interface cho Các dạng Textarea.
19
+ */
20
+ export class TextareaField extends BaseField<string> {
21
+ /**
22
+ * Props validation chung cho dạng Textarea.
23
+ */
24
+ // Độ dài tối thiểu của chuỗi nhập vào.
25
+ minLength?: number;
26
+ // Độ dài tối đa của chuỗi nhập vào.
27
+ maxLength?: number;
28
+ // Theo mẫu regex hoặc đối tượng RegExr
29
+ pattern?: string | RegExp;
30
+
31
+ constructor(init: Partial<TextareaField>) {
32
+ super(init);
33
+
34
+ /**
35
+ * Gán giá trị cho các props cần giá trị mặc định ở Input.
36
+ */
37
+ this.controlType = ControlTypeEnum.Textarea;
38
+ this.type = FieldTypeEnum.Textarea;
39
+ this.value = DEFAULT_TEXTAREA_VALUE;
40
+ this.initialValue = DEFAULT_TEXTAREA_VALUE;
41
+
42
+ Object.assign(this, init);
43
+ }
44
+
45
+ // Mảng ValidatorFn các validation chung được hỗ trợ sẵn bởi Reactive form của angular cho Input.
46
+ protected getCommonTextareaValidators(): ValidatorFn[] {
47
+ const validators = this.getCommonValidators();
48
+
49
+ if (this.minLength) validators.push(Validators.minLength(this.minLength));
50
+ if (this.maxLength) validators.push(Validators.maxLength(this.maxLength));
51
+ if (this.pattern) {
52
+ const resolvePatternResult = resolvePattern(this.pattern);
53
+ if (resolvePatternResult?.type !== 'unknown')
54
+ validators.push(Validators.pattern(resolvePatternResult.value));
55
+ }
56
+
57
+ return validators;
58
+ }
59
+
60
+ // Mảng ValidatorFn các custom validation có thể dùng cho Input.
61
+ protected getCustomTextareaValidators(): ValidatorFn[] {
62
+ const validators = this.getCustomValidators();
63
+
64
+ validators.push(noLeadingSpaceValidator());
65
+
66
+ return validators;
67
+ }
68
+
69
+ // Tạo Form Control cho Input Field.
70
+ override toFormControl(): FormControl {
71
+ const commonValidators = this.getCommonTextareaValidators();
72
+ const customValidators = this.getCustomTextareaValidators();
73
+ return new FormControl(this.value ?? '', [...commonValidators, ...customValidators]);
74
+ }
75
+
76
+ // Giá trị mặc định.
77
+ override getDefaultValue(): string {
78
+ return DEFAULT_TEXTAREA_VALUE;
79
+ }
80
+
81
+ override toFormValue(modelValue: unknown): string {
82
+ return String(modelValue);
83
+ }
84
+
85
+ override getErrorMessage(errorKey: string, errorValue: any, allFields: BaseField<any>[]): string {
86
+ if (errorKey === CommonValidaterEnum.Pattern) {
87
+ if (this.pattern) return getDefaultPatternErrorMessage(this.label, this.pattern);
88
+ }
89
+ if (errorKey === CommonValidaterEnum.MinLength)
90
+ return getDefaultMinLengthErrorMessage(this.label, errorValue);
91
+ if (errorKey === CommonValidaterEnum.MaxLength)
92
+ return getDefaultMaxLengthErrorMessage(this.label, errorValue);
93
+ if (errorKey === CustomValidaterEnum.LeadingSpace)
94
+ return getLeadingSpaceErrorMessage(this.label);
95
+ return super.getErrorMessage(errorKey, errorValue, allFields);
96
+ }
97
+ }