@rxap/forms 21.0.1-dev.0 → 21.0.1-dev.1

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 (426) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/compodoc/changelog.html +12 -0
  3. package/compodoc/dependencies.html +8 -8
  4. package/compodoc/directives/FormControlErrorDirective.html +97 -166
  5. package/compodoc/directives/FormControlMarkDirtyDirective.html +5 -107
  6. package/compodoc/directives/FormControlMarkPristineDirective.html +5 -107
  7. package/compodoc/directives/FormControlMarkTouchedDirective.html +5 -107
  8. package/compodoc/directives/FormControlMarkUntouchedDirective.html +5 -107
  9. package/compodoc/directives/FormControlNameDirective.html +12 -124
  10. package/compodoc/directives/FormDirective.html +1032 -1057
  11. package/compodoc/directives/FormGroupNameDirective.html +16 -111
  12. package/compodoc/directives/FormLoadedDirective.html +16 -96
  13. package/compodoc/directives/FormLoadingDirective.html +16 -96
  14. package/compodoc/directives/FormLoadingErrorDirective.html +15 -91
  15. package/compodoc/directives/FormResetDirective.html +47 -101
  16. package/compodoc/directives/FormSubmitDirective.html +45 -100
  17. package/compodoc/directives/FormSubmitFailedDirective.html +15 -91
  18. package/compodoc/directives/FormSubmitInvalidDirective.html +14 -95
  19. package/compodoc/directives/FormSubmitSuccessfulDirective.html +14 -95
  20. package/compodoc/directives/FormSubmittingDirective.html +16 -96
  21. package/compodoc/graph/dependencies.svg +15 -441
  22. package/compodoc/js/menu-wc.js +0 -77
  23. package/compodoc/js/menu-wc_es5.js +1 -1
  24. package/compodoc/js/search/search_index.js +2 -2
  25. package/compodoc/modules.html +0 -17
  26. package/compodoc/overview.html +1 -473
  27. package/compodoc/properties.html +1 -1
  28. package/docs/documentation.json +8980 -11445
  29. package/docs/html/assets/hierarchy.js +1 -1
  30. package/docs/html/assets/navigation.js +1 -1
  31. package/docs/html/assets/search.js +1 -1
  32. package/docs/html/classes/ControlValueAccessor.html +5 -5
  33. package/docs/html/classes/FormArrayControlManager.html +2 -2
  34. package/docs/html/classes/FormControlErrorDirective.html +3 -12
  35. package/docs/html/classes/FormControlMarkDirtyDirective.html +2 -2
  36. package/docs/html/classes/FormControlMarkPristineDirective.html +2 -2
  37. package/docs/html/classes/FormControlMarkTouchedDirective.html +2 -2
  38. package/docs/html/classes/FormControlMarkUntouchedDirective.html +2 -2
  39. package/docs/html/classes/FormControlNameDirective.html +8 -8
  40. package/docs/html/classes/FormDirective.html +41 -28
  41. package/docs/html/classes/FormGroupNameDirective.html +7 -7
  42. package/docs/html/classes/FormLoadedDirective.html +2 -9
  43. package/docs/html/classes/FormLoadingDirective.html +2 -9
  44. package/docs/html/classes/FormLoadingErrorDirective.html +2 -9
  45. package/docs/html/classes/FormResetDirective.html +4 -4
  46. package/docs/html/classes/FormSubmitDirective.html +4 -4
  47. package/docs/html/classes/FormSubmitFailedDirective.html +2 -9
  48. package/docs/html/classes/FormSubmitInvalidDirective.html +2 -9
  49. package/docs/html/classes/FormSubmitSuccessfulDirective.html +2 -9
  50. package/docs/html/classes/FormSubmittingDirective.html +2 -9
  51. package/docs/html/classes/ParentControlContainerDirective.html +2 -2
  52. package/docs/html/classes/RxapFormArray.html +35 -35
  53. package/docs/html/classes/RxapFormBuilder.html +2 -2
  54. package/docs/html/classes/RxapFormControl.html +30 -30
  55. package/docs/html/classes/RxapFormGroup.html +35 -35
  56. package/docs/html/enums/MetadataKeys.html +2 -2
  57. package/docs/html/functions/ControlAsyncValidator.html +1 -1
  58. package/docs/html/functions/ControlChange.html +1 -1
  59. package/docs/html/functions/ControlSetValue.html +1 -1
  60. package/docs/html/functions/ControlValidator.html +1 -1
  61. package/docs/html/functions/IsArray.html +1 -1
  62. package/docs/html/functions/IsBoolean.html +1 -1
  63. package/docs/html/functions/IsComplex.html +1 -1
  64. package/docs/html/functions/IsDate.html +1 -1
  65. package/docs/html/functions/IsEmail.html +1 -1
  66. package/docs/html/functions/IsEnum.html +1 -1
  67. package/docs/html/functions/IsIP.html +1 -1
  68. package/docs/html/functions/IsInt.html +1 -1
  69. package/docs/html/functions/IsNumber-1.html +2 -2
  70. package/docs/html/functions/IsObject.html +1 -1
  71. package/docs/html/functions/IsPhoneNumber.html +1 -1
  72. package/docs/html/functions/IsPort.html +1 -1
  73. package/docs/html/functions/IsString.html +1 -1
  74. package/docs/html/functions/IsUUID.html +1 -1
  75. package/docs/html/functions/IsUrl.html +1 -1
  76. package/docs/html/functions/RxapForm.html +1 -1
  77. package/docs/html/functions/ToFormMethod.html +1 -1
  78. package/docs/html/functions/ToFormSubmitMethod.html +2 -2
  79. package/docs/html/functions/UseFormArrayControl.html +1 -1
  80. package/docs/html/functions/UseFormArrayGroup.html +1 -1
  81. package/docs/html/functions/UseFormControl.html +1 -1
  82. package/docs/html/functions/UseFormGroup.html +1 -1
  83. package/docs/html/functions/_IsNumber.html +1 -1
  84. package/docs/html/functions/controlDisabledWhile.html +1 -1
  85. package/docs/html/functions/controlDisabled_.html +1 -1
  86. package/docs/html/functions/controlEnabledWhile.html +1 -1
  87. package/docs/html/functions/controlEnabled_.html +1 -1
  88. package/docs/html/functions/controlErrorChanges_.html +1 -1
  89. package/docs/html/functions/controlReadonly_.html +1 -1
  90. package/docs/html/functions/controlStatusChanges_.html +1 -1
  91. package/docs/html/functions/controlValueChanges_.html +1 -1
  92. package/docs/html/functions/disableControl.html +1 -1
  93. package/docs/html/functions/enableControl.html +1 -1
  94. package/docs/html/functions/hasErrorAndDirty.html +1 -1
  95. package/docs/html/functions/hasErrorAndTouched.html +1 -1
  96. package/docs/html/functions/isNumber.html +2 -2
  97. package/docs/html/functions/markAllDirty.html +1 -1
  98. package/docs/html/functions/markAllPristine.html +1 -1
  99. package/docs/html/functions/markAllUntouched.html +1 -1
  100. package/docs/html/functions/mergeControlValidators.html +1 -1
  101. package/docs/html/functions/selectControlValue_.html +1 -1
  102. package/docs/html/functions/validateControlOn.html +1 -1
  103. package/docs/html/hierarchy.html +1 -1
  104. package/docs/html/index.html +2 -2
  105. package/docs/html/interfaces/AbstractControl.html +5 -5
  106. package/docs/html/interfaces/AbstractControlOptions.html +3 -3
  107. package/docs/html/interfaces/BoxedValue.html +2 -2
  108. package/docs/html/interfaces/ComplexityOptions.html +2 -2
  109. package/docs/html/interfaces/ControlOptions.html +3 -3
  110. package/docs/html/interfaces/ControlSetValueOptions.html +2 -2
  111. package/docs/html/interfaces/FormArrayOptions.html +3 -3
  112. package/docs/html/interfaces/FormDefinition.html +6 -6
  113. package/docs/html/interfaces/FormDefinitionArray.html +3 -3
  114. package/docs/html/interfaces/FormDefinitionMetadata.html +3 -3
  115. package/docs/html/interfaces/FormGroupOptions.html +3 -3
  116. package/docs/html/interfaces/FormLoadFailedMethod.html +2 -2
  117. package/docs/html/interfaces/FormLoadMethod.html +2 -2
  118. package/docs/html/interfaces/FormLoadSuccessfulMethod.html +2 -2
  119. package/docs/html/interfaces/FormOptions.html +3 -3
  120. package/docs/html/interfaces/FormSubmitFailedMethod.html +2 -2
  121. package/docs/html/interfaces/FormSubmitMethod.html +2 -2
  122. package/docs/html/interfaces/FormSubmitSuccessfulMethod.html +2 -2
  123. package/docs/html/interfaces/InjectableValidator.html +2 -2
  124. package/docs/html/interfaces/IsNumberOptions.html +3 -3
  125. package/docs/html/interfaces/NgValidatorsErrors.html +2 -2
  126. package/docs/html/interfaces/RxapAbstractControlOptionsWithDefinition.html +3 -3
  127. package/docs/html/interfaces/_RxapAbstractControlOptions.html +3 -3
  128. package/docs/html/modules.html +1 -1
  129. package/docs/html/types/AsyncValidator.html +1 -1
  130. package/docs/html/types/AsyncValidatorFn.html +1 -1
  131. package/docs/html/types/ChangeFn.html +1 -1
  132. package/docs/html/types/ControlEventOptions.html +1 -1
  133. package/docs/html/types/ControlInsertedFn.html +1 -1
  134. package/docs/html/types/ControlPath.html +1 -1
  135. package/docs/html/types/ControlRemovedFn.html +1 -1
  136. package/docs/html/types/ControlState.html +1 -1
  137. package/docs/html/types/EmitEvent.html +1 -1
  138. package/docs/html/types/ExtractAbstractControl.html +1 -1
  139. package/docs/html/types/ExtractStrings.html +1 -1
  140. package/docs/html/types/FormBuilderFn.html +1 -1
  141. package/docs/html/types/FormType.html +1 -1
  142. package/docs/html/types/KeyValueControls.html +1 -1
  143. package/docs/html/types/OnlySelf.html +1 -1
  144. package/docs/html/types/OrBoxedValue.html +1 -1
  145. package/docs/html/types/RxapAbstractControlOptions.html +1 -1
  146. package/docs/html/types/SetValueFn.html +1 -1
  147. package/docs/html/types/ValidationErrors.html +1 -1
  148. package/docs/html/types/Validator.html +1 -1
  149. package/docs/html/types/ValidatorFn.html +1 -1
  150. package/docs/html/types/ValidatorOrOpts.html +1 -1
  151. package/docs/html/variables/RXAP_FORM_CONTEXT.html +1 -1
  152. package/docs/html/variables/RXAP_FORM_DEFINITION.html +1 -1
  153. package/docs/html/variables/RXAP_FORM_DEFINITION_BUILDER.html +1 -1
  154. package/docs/html/variables/RXAP_FORM_INITIAL_STATE.html +1 -1
  155. package/docs/html/variables/RXAP_FORM_LOAD_FAILED_METHOD.html +1 -1
  156. package/docs/html/variables/RXAP_FORM_LOAD_METHOD.html +1 -1
  157. package/docs/html/variables/RXAP_FORM_LOAD_SUCCESSFUL_METHOD.html +1 -1
  158. package/docs/html/variables/RXAP_FORM_SUBMIT_FAILED_METHOD.html +1 -1
  159. package/docs/html/variables/RXAP_FORM_SUBMIT_METHOD.html +1 -1
  160. package/docs/html/variables/RXAP_FORM_SUBMIT_SUCCESSFUL_METHOD.html +1 -1
  161. package/docs/html/variables/RxapValidators.html +1 -1
  162. package/docs/markdown/README.md +1 -1
  163. package/docs/markdown/classes/ControlValueAccessor.md +8 -8
  164. package/docs/markdown/classes/FormArrayControlManager.md +5 -5
  165. package/docs/markdown/classes/FormControlErrorDirective.md +8 -68
  166. package/docs/markdown/classes/FormControlMarkDirtyDirective.md +4 -12
  167. package/docs/markdown/classes/FormControlMarkPristineDirective.md +4 -12
  168. package/docs/markdown/classes/FormControlMarkTouchedDirective.md +4 -12
  169. package/docs/markdown/classes/FormControlMarkUntouchedDirective.md +4 -12
  170. package/docs/markdown/classes/FormControlNameDirective.md +7 -25
  171. package/docs/markdown/classes/FormDirective.md +158 -175
  172. package/docs/markdown/classes/FormGroupNameDirective.md +7 -21
  173. package/docs/markdown/classes/FormLoadedDirective.md +4 -62
  174. package/docs/markdown/classes/FormLoadingDirective.md +4 -62
  175. package/docs/markdown/classes/FormLoadingErrorDirective.md +4 -62
  176. package/docs/markdown/classes/FormResetDirective.md +15 -35
  177. package/docs/markdown/classes/FormSubmitDirective.md +33 -57
  178. package/docs/markdown/classes/FormSubmitFailedDirective.md +4 -62
  179. package/docs/markdown/classes/FormSubmitInvalidDirective.md +4 -62
  180. package/docs/markdown/classes/FormSubmitSuccessfulDirective.md +4 -62
  181. package/docs/markdown/classes/FormSubmittingDirective.md +4 -62
  182. package/docs/markdown/classes/ParentControlContainerDirective.md +2 -2
  183. package/docs/markdown/classes/RxapFormArray.md +54 -54
  184. package/docs/markdown/classes/RxapFormBuilder.md +4 -4
  185. package/docs/markdown/classes/RxapFormControl.md +51 -51
  186. package/docs/markdown/classes/RxapFormGroup.md +74 -74
  187. package/docs/markdown/enumerations/MetadataKeys.md +10 -10
  188. package/docs/markdown/functions/ControlAsyncValidator.md +2 -2
  189. package/docs/markdown/functions/ControlChange.md +2 -2
  190. package/docs/markdown/functions/ControlSetValue.md +2 -2
  191. package/docs/markdown/functions/ControlValidator.md +2 -2
  192. package/docs/markdown/functions/IsArray.md +2 -2
  193. package/docs/markdown/functions/IsBoolean.md +2 -2
  194. package/docs/markdown/functions/IsComplex.md +2 -2
  195. package/docs/markdown/functions/IsDate.md +2 -2
  196. package/docs/markdown/functions/IsEmail.md +2 -2
  197. package/docs/markdown/functions/IsEnum.md +2 -2
  198. package/docs/markdown/functions/IsIP.md +2 -2
  199. package/docs/markdown/functions/IsInt.md +2 -2
  200. package/docs/markdown/functions/IsNumber-2.md +2 -2
  201. package/docs/markdown/functions/IsNumber.md +2 -2
  202. package/docs/markdown/functions/IsObject.md +2 -2
  203. package/docs/markdown/functions/IsPhoneNumber.md +2 -2
  204. package/docs/markdown/functions/IsPort.md +2 -2
  205. package/docs/markdown/functions/IsString.md +2 -2
  206. package/docs/markdown/functions/IsUUID.md +2 -2
  207. package/docs/markdown/functions/IsUrl.md +2 -2
  208. package/docs/markdown/functions/RxapForm.md +2 -2
  209. package/docs/markdown/functions/ToFormMethod.md +2 -2
  210. package/docs/markdown/functions/ToFormSubmitMethod.md +2 -2
  211. package/docs/markdown/functions/UseFormArrayControl.md +2 -2
  212. package/docs/markdown/functions/UseFormArrayGroup.md +2 -2
  213. package/docs/markdown/functions/UseFormControl.md +2 -2
  214. package/docs/markdown/functions/UseFormGroup.md +2 -2
  215. package/docs/markdown/functions/controlDisabled$.md +2 -2
  216. package/docs/markdown/functions/controlDisabledWhile.md +2 -2
  217. package/docs/markdown/functions/controlEnabled$.md +2 -2
  218. package/docs/markdown/functions/controlEnabledWhile.md +2 -2
  219. package/docs/markdown/functions/controlErrorChanges$.md +2 -2
  220. package/docs/markdown/functions/controlReadonly$.md +2 -2
  221. package/docs/markdown/functions/controlStatusChanges$.md +2 -2
  222. package/docs/markdown/functions/controlValueChanges$.md +2 -2
  223. package/docs/markdown/functions/disableControl.md +2 -2
  224. package/docs/markdown/functions/enableControl.md +2 -2
  225. package/docs/markdown/functions/hasErrorAndDirty.md +2 -2
  226. package/docs/markdown/functions/hasErrorAndTouched.md +2 -2
  227. package/docs/markdown/functions/isNumber-1.md +2 -2
  228. package/docs/markdown/functions/markAllDirty.md +2 -2
  229. package/docs/markdown/functions/markAllPristine.md +2 -2
  230. package/docs/markdown/functions/markAllUntouched.md +2 -2
  231. package/docs/markdown/functions/mergeControlValidators.md +2 -2
  232. package/docs/markdown/functions/selectControlValue$.md +2 -2
  233. package/docs/markdown/functions/validateControlOn.md +2 -2
  234. package/docs/markdown/globals.md +2 -3
  235. package/docs/markdown/interfaces/AbstractControl.md +8 -8
  236. package/docs/markdown/interfaces/AbstractControlOptions.md +5 -5
  237. package/docs/markdown/interfaces/BoxedValue.md +4 -4
  238. package/docs/markdown/interfaces/ComplexityOptions.md +12 -12
  239. package/docs/markdown/interfaces/ControlOptions.md +10 -10
  240. package/docs/markdown/interfaces/ControlSetValueOptions.md +4 -4
  241. package/docs/markdown/interfaces/FormArrayOptions.md +12 -12
  242. package/docs/markdown/interfaces/FormDefinition.md +7 -7
  243. package/docs/markdown/interfaces/FormDefinitionArray.md +3 -3
  244. package/docs/markdown/interfaces/FormDefinitionMetadata.md +11 -11
  245. package/docs/markdown/interfaces/FormGroupOptions.md +9 -9
  246. package/docs/markdown/interfaces/FormLoadFailedMethod.md +4 -4
  247. package/docs/markdown/interfaces/FormLoadMethod.md +4 -4
  248. package/docs/markdown/interfaces/FormLoadSuccessfulMethod.md +4 -4
  249. package/docs/markdown/interfaces/FormOptions.md +9 -9
  250. package/docs/markdown/interfaces/FormSubmitFailedMethod.md +4 -4
  251. package/docs/markdown/interfaces/FormSubmitMethod.md +4 -4
  252. package/docs/markdown/interfaces/FormSubmitSuccessfulMethod.md +4 -4
  253. package/docs/markdown/interfaces/InjectableValidator.md +4 -4
  254. package/docs/markdown/interfaces/IsNumberOptions.md +6 -6
  255. package/docs/markdown/interfaces/NgValidatorsErrors.md +9 -9
  256. package/docs/markdown/interfaces/RxapAbstractControlOptions.md +8 -8
  257. package/docs/markdown/interfaces/RxapAbstractControlOptionsWithDefinition.md +9 -9
  258. package/docs/markdown/type-aliases/AsyncValidator.md +2 -2
  259. package/docs/markdown/type-aliases/AsyncValidatorFn.md +2 -2
  260. package/docs/markdown/type-aliases/ChangeFn.md +2 -2
  261. package/docs/markdown/type-aliases/ControlEventOptions.md +2 -2
  262. package/docs/markdown/type-aliases/ControlInsertedFn.md +2 -2
  263. package/docs/markdown/type-aliases/ControlPath.md +2 -2
  264. package/docs/markdown/type-aliases/ControlRemovedFn.md +2 -2
  265. package/docs/markdown/type-aliases/ControlState.md +2 -2
  266. package/docs/markdown/type-aliases/EmitEvent.md +2 -2
  267. package/docs/markdown/type-aliases/ExtractAbstractControl.md +2 -2
  268. package/docs/markdown/type-aliases/ExtractStrings.md +2 -2
  269. package/docs/markdown/type-aliases/FormBuilderFn.md +2 -2
  270. package/docs/markdown/type-aliases/FormType.md +2 -2
  271. package/docs/markdown/type-aliases/KeyValueControls.md +2 -2
  272. package/docs/markdown/type-aliases/OnlySelf.md +2 -2
  273. package/docs/markdown/type-aliases/OrBoxedValue.md +2 -2
  274. package/docs/markdown/type-aliases/RxapAbstractControlOptions.md +2 -2
  275. package/docs/markdown/type-aliases/SetValueFn.md +2 -2
  276. package/docs/markdown/type-aliases/ValidationErrors.md +2 -2
  277. package/docs/markdown/type-aliases/Validator.md +2 -2
  278. package/docs/markdown/type-aliases/ValidatorFn.md +2 -2
  279. package/docs/markdown/type-aliases/ValidatorOrOpts.md +2 -2
  280. package/docs/markdown/variables/RXAP_FORM_CONTEXT.md +2 -2
  281. package/docs/markdown/variables/RXAP_FORM_DEFINITION.md +2 -2
  282. package/docs/markdown/variables/RXAP_FORM_DEFINITION_BUILDER.md +2 -2
  283. package/docs/markdown/variables/RXAP_FORM_INITIAL_STATE.md +2 -2
  284. package/docs/markdown/variables/RXAP_FORM_LOAD_FAILED_METHOD.md +2 -2
  285. package/docs/markdown/variables/RXAP_FORM_LOAD_METHOD.md +2 -2
  286. package/docs/markdown/variables/RXAP_FORM_LOAD_SUCCESSFUL_METHOD.md +2 -2
  287. package/docs/markdown/variables/RXAP_FORM_SUBMIT_FAILED_METHOD.md +2 -2
  288. package/docs/markdown/variables/RXAP_FORM_SUBMIT_METHOD.md +2 -2
  289. package/docs/markdown/variables/RXAP_FORM_SUBMIT_SUCCESSFUL_METHOD.md +2 -2
  290. package/docs/markdown/variables/RxapValidators.md +2 -2
  291. package/docs/wiki/Class.ControlValueAccessor.md +7 -7
  292. package/docs/wiki/Class.FormArrayControlManager.md +4 -4
  293. package/docs/wiki/Class.FormControlErrorDirective.md +7 -67
  294. package/docs/wiki/Class.FormControlMarkDirtyDirective.md +3 -11
  295. package/docs/wiki/Class.FormControlMarkPristineDirective.md +3 -11
  296. package/docs/wiki/Class.FormControlMarkTouchedDirective.md +3 -11
  297. package/docs/wiki/Class.FormControlMarkUntouchedDirective.md +3 -11
  298. package/docs/wiki/Class.FormControlNameDirective.md +6 -24
  299. package/docs/wiki/Class.FormDirective.md +157 -174
  300. package/docs/wiki/Class.FormGroupNameDirective.md +6 -20
  301. package/docs/wiki/Class.FormLoadedDirective.md +3 -61
  302. package/docs/wiki/Class.FormLoadingDirective.md +3 -61
  303. package/docs/wiki/Class.FormLoadingErrorDirective.md +3 -61
  304. package/docs/wiki/Class.FormResetDirective.md +14 -34
  305. package/docs/wiki/Class.FormSubmitDirective.md +32 -56
  306. package/docs/wiki/Class.FormSubmitFailedDirective.md +3 -61
  307. package/docs/wiki/Class.FormSubmitInvalidDirective.md +3 -61
  308. package/docs/wiki/Class.FormSubmitSuccessfulDirective.md +3 -61
  309. package/docs/wiki/Class.FormSubmittingDirective.md +3 -61
  310. package/docs/wiki/Class.ParentControlContainerDirective.md +1 -1
  311. package/docs/wiki/Class.RxapFormArray.md +53 -53
  312. package/docs/wiki/Class.RxapFormBuilder.md +3 -3
  313. package/docs/wiki/Class.RxapFormControl.md +50 -50
  314. package/docs/wiki/Class.RxapFormGroup.md +73 -73
  315. package/docs/wiki/Enumeration.MetadataKeys.md +9 -9
  316. package/docs/wiki/Function.ControlAsyncValidator.md +1 -1
  317. package/docs/wiki/Function.ControlChange.md +1 -1
  318. package/docs/wiki/Function.ControlSetValue.md +1 -1
  319. package/docs/wiki/Function.ControlValidator.md +1 -1
  320. package/docs/wiki/Function.IsArray.md +1 -1
  321. package/docs/wiki/Function.IsBoolean.md +1 -1
  322. package/docs/wiki/Function.IsComplex.md +1 -1
  323. package/docs/wiki/Function.IsDate.md +1 -1
  324. package/docs/wiki/Function.IsEmail.md +1 -1
  325. package/docs/wiki/Function.IsEnum.md +1 -1
  326. package/docs/wiki/Function.IsIP.md +1 -1
  327. package/docs/wiki/Function.IsInt.md +1 -1
  328. package/docs/wiki/Function.IsNumber.md +1 -1
  329. package/docs/wiki/Function.IsObject.md +1 -1
  330. package/docs/wiki/Function.IsPhoneNumber.md +1 -1
  331. package/docs/wiki/Function.IsPort.md +1 -1
  332. package/docs/wiki/Function.IsString.md +1 -1
  333. package/docs/wiki/Function.IsUUID.md +1 -1
  334. package/docs/wiki/Function.IsUrl.md +1 -1
  335. package/docs/wiki/Function.RxapForm.md +1 -1
  336. package/docs/wiki/Function.ToFormMethod.md +1 -1
  337. package/docs/wiki/Function.ToFormSubmitMethod.md +1 -1
  338. package/docs/wiki/Function.UseFormArrayControl.md +1 -1
  339. package/docs/wiki/Function.UseFormArrayGroup.md +1 -1
  340. package/docs/wiki/Function.UseFormControl.md +1 -1
  341. package/docs/wiki/Function.UseFormGroup.md +1 -1
  342. package/docs/wiki/Function._IsNumber.md +1 -1
  343. package/docs/wiki/Function.controlDisabled$.md +1 -1
  344. package/docs/wiki/Function.controlDisabledWhile.md +1 -1
  345. package/docs/wiki/Function.controlEnabled$.md +1 -1
  346. package/docs/wiki/Function.controlEnabledWhile.md +1 -1
  347. package/docs/wiki/Function.controlErrorChanges$.md +1 -1
  348. package/docs/wiki/Function.controlReadonly$.md +1 -1
  349. package/docs/wiki/Function.controlStatusChanges$.md +1 -1
  350. package/docs/wiki/Function.controlValueChanges$.md +1 -1
  351. package/docs/wiki/Function.disableControl.md +1 -1
  352. package/docs/wiki/Function.enableControl.md +1 -1
  353. package/docs/wiki/Function.hasErrorAndDirty.md +1 -1
  354. package/docs/wiki/Function.hasErrorAndTouched.md +1 -1
  355. package/docs/wiki/Function.isNumber.md +1 -1
  356. package/docs/wiki/Function.markAllDirty.md +1 -1
  357. package/docs/wiki/Function.markAllPristine.md +1 -1
  358. package/docs/wiki/Function.markAllUntouched.md +1 -1
  359. package/docs/wiki/Function.mergeControlValidators.md +1 -1
  360. package/docs/wiki/Function.selectControlValue$.md +1 -1
  361. package/docs/wiki/Function.validateControlOn.md +1 -1
  362. package/docs/wiki/Interface.AbstractControl.md +7 -7
  363. package/docs/wiki/Interface.AbstractControlOptions.md +4 -4
  364. package/docs/wiki/Interface.BoxedValue.md +3 -3
  365. package/docs/wiki/Interface.ComplexityOptions.md +11 -11
  366. package/docs/wiki/Interface.ControlOptions.md +9 -9
  367. package/docs/wiki/Interface.ControlSetValueOptions.md +3 -3
  368. package/docs/wiki/Interface.FormArrayOptions.md +11 -11
  369. package/docs/wiki/Interface.FormDefinition.md +6 -6
  370. package/docs/wiki/Interface.FormDefinitionArray.md +2 -2
  371. package/docs/wiki/Interface.FormDefinitionMetadata.md +10 -10
  372. package/docs/wiki/Interface.FormGroupOptions.md +8 -8
  373. package/docs/wiki/Interface.FormLoadFailedMethod.md +3 -3
  374. package/docs/wiki/Interface.FormLoadMethod.md +3 -3
  375. package/docs/wiki/Interface.FormLoadSuccessfulMethod.md +3 -3
  376. package/docs/wiki/Interface.FormOptions.md +8 -8
  377. package/docs/wiki/Interface.FormSubmitFailedMethod.md +3 -3
  378. package/docs/wiki/Interface.FormSubmitMethod.md +3 -3
  379. package/docs/wiki/Interface.FormSubmitSuccessfulMethod.md +3 -3
  380. package/docs/wiki/Interface.InjectableValidator.md +3 -3
  381. package/docs/wiki/Interface.IsNumberOptions.md +5 -5
  382. package/docs/wiki/Interface.NgValidatorsErrors.md +8 -8
  383. package/docs/wiki/Interface.RxapAbstractControlOptionsWithDefinition.md +8 -8
  384. package/docs/wiki/Interface._RxapAbstractControlOptions.md +7 -7
  385. package/docs/wiki/TypeAlias.AsyncValidator.md +1 -1
  386. package/docs/wiki/TypeAlias.AsyncValidatorFn.md +1 -1
  387. package/docs/wiki/TypeAlias.ChangeFn.md +1 -1
  388. package/docs/wiki/TypeAlias.ControlEventOptions.md +1 -1
  389. package/docs/wiki/TypeAlias.ControlInsertedFn.md +1 -1
  390. package/docs/wiki/TypeAlias.ControlPath.md +1 -1
  391. package/docs/wiki/TypeAlias.ControlRemovedFn.md +1 -1
  392. package/docs/wiki/TypeAlias.ControlState.md +1 -1
  393. package/docs/wiki/TypeAlias.EmitEvent.md +1 -1
  394. package/docs/wiki/TypeAlias.ExtractAbstractControl.md +1 -1
  395. package/docs/wiki/TypeAlias.ExtractStrings.md +1 -1
  396. package/docs/wiki/TypeAlias.FormBuilderFn.md +1 -1
  397. package/docs/wiki/TypeAlias.FormType.md +1 -1
  398. package/docs/wiki/TypeAlias.KeyValueControls.md +1 -1
  399. package/docs/wiki/TypeAlias.OnlySelf.md +1 -1
  400. package/docs/wiki/TypeAlias.OrBoxedValue.md +1 -1
  401. package/docs/wiki/TypeAlias.RxapAbstractControlOptions.md +1 -1
  402. package/docs/wiki/TypeAlias.SetValueFn.md +1 -1
  403. package/docs/wiki/TypeAlias.ValidationErrors.md +1 -1
  404. package/docs/wiki/TypeAlias.Validator.md +1 -1
  405. package/docs/wiki/TypeAlias.ValidatorFn.md +1 -1
  406. package/docs/wiki/TypeAlias.ValidatorOrOpts.md +1 -1
  407. package/docs/wiki/Variable.RXAP_FORM_CONTEXT.md +1 -1
  408. package/docs/wiki/Variable.RXAP_FORM_DEFINITION.md +1 -1
  409. package/docs/wiki/Variable.RXAP_FORM_DEFINITION_BUILDER.md +1 -1
  410. package/docs/wiki/Variable.RXAP_FORM_INITIAL_STATE.md +1 -1
  411. package/docs/wiki/Variable.RXAP_FORM_LOAD_FAILED_METHOD.md +1 -1
  412. package/docs/wiki/Variable.RXAP_FORM_LOAD_METHOD.md +1 -1
  413. package/docs/wiki/Variable.RXAP_FORM_LOAD_SUCCESSFUL_METHOD.md +1 -1
  414. package/docs/wiki/Variable.RXAP_FORM_SUBMIT_FAILED_METHOD.md +1 -1
  415. package/docs/wiki/Variable.RXAP_FORM_SUBMIT_METHOD.md +1 -1
  416. package/docs/wiki/Variable.RXAP_FORM_SUBMIT_SUCCESSFUL_METHOD.md +1 -1
  417. package/docs/wiki/Variable.RxapValidators.md +1 -1
  418. package/docs/wiki/_Sidebar.md +0 -1
  419. package/docs/wiki/globals.md +1 -2
  420. package/fesm2022/rxap-forms.mjs +1850 -2170
  421. package/fesm2022/rxap-forms.mjs.map +1 -1
  422. package/package.json +17 -17
  423. package/types/rxap-forms.d.ts +400 -410
  424. package/docs/html/classes/RxapFormsModule.html +0 -2
  425. package/docs/markdown/classes/RxapFormsModule.md +0 -19
  426. package/docs/wiki/Class.RxapFormsModule.md +0 -15
@@ -1,20 +1,17 @@
1
1
  import { isEmail, isIP, isMobilePhone, isPort, isURL, isUUID } from '@rxap/validator';
2
2
  import * as i0 from '@angular/core';
3
- import { Input, Host, SkipSelf, Directive, HostListener, forwardRef, Optional, Self, Inject, InjectionToken, isDevMode, Injector, model, EventEmitter, ChangeDetectorRef, HostBinding, Output, TemplateRef, ViewContainerRef, input, output, computed, NgModule } from '@angular/core';
4
- import * as i1 from '@angular/forms';
5
- import { FormControlName, NG_VALIDATORS, NG_ASYNC_VALIDATORS, NG_VALUE_ACCESSOR, NgControl, FormGroupName, ControlContainer, UntypedFormArray, AbstractControl, UntypedFormGroup, UntypedFormControl, Validators, FormGroupDirective } from '@angular/forms';
6
- import { startWith, filter, tap, map, distinctUntilChanged, debounceTime, take } from 'rxjs/operators';
7
- import { hasIndexSignature, equals, coerceArray, HasRxapOnInitMethod, assertIsArray, assertIsObject, assertIsFunction, isPromise, isObject, clone, coerceBoolean } from '@rxap/utilities';
3
+ import { inject, TemplateRef, ViewContainerRef, input, effect, untracked, Directive, forwardRef, InjectionToken, ChangeDetectorRef, computed, output, isDevMode, Injector } from '@angular/core';
4
+ import { ControlContainer, FormControlName, NG_VALIDATORS, NG_ASYNC_VALIDATORS, NG_VALUE_ACCESSOR, NgControl, FormGroupName, FormGroupDirective, UntypedFormArray, AbstractControl, UntypedFormGroup, UntypedFormControl, Validators } from '@angular/forms';
5
+ import { startWith, tap, debounceTime, filter, take, map, distinctUntilChanged } from 'rxjs/operators';
6
+ import { hasIndexSignature, isPromise, isObject, clone, coerceBoolean, equals, coerceArray, HasRxapOnInitMethod, assertIsArray, assertIsObject, assertIsFunction } from '@rxap/utilities';
7
+ import { toSignal, outputToObservable, takeUntilDestroyed } from '@angular/core/rxjs-interop';
8
8
  import { ToggleSubject } from '@rxap/rxjs';
9
- import * as i2 from '@rxap/services';
10
9
  import { LoadingIndicatorService } from '@rxap/services';
11
- import { merge, defer, of, EMPTY, Subject, isObservable, BehaviorSubject, Subscription } from 'rxjs';
12
- import { GetDefinitionMetadata, DefinitionMetadata } from '@rxap/definition';
13
- import { getMetadata, setMetadataMapSet, setMetadataMap } from '@rxap/reflect-metadata';
10
+ import { BehaviorSubject, Subscription, merge, defer, of, EMPTY, Subject, isObservable } from 'rxjs';
14
11
  import { ConfirmClick } from '@rxap/directives';
15
- import { toSignal } from '@angular/core/rxjs-interop';
16
- import * as i2$1 from '@angular/router';
17
12
  import { Router } from '@angular/router';
13
+ import { setMetadataMapSet, setMetadataMap, getMetadata } from '@rxap/reflect-metadata';
14
+ import { DefinitionMetadata, GetDefinitionMetadata } from '@rxap/definition';
18
15
 
19
16
  function IsArray({ message } = {}) {
20
17
  return (control) => {
@@ -273,7 +270,7 @@ function IsInt({ message, options, } = {}) {
273
270
  if (control.value === null) {
274
271
  return null;
275
272
  }
276
- if (!isNumber(control.value, options) || Number.isInteger(control.value)) {
273
+ if (!isNumber(control.value, options) || !Number.isInteger(control.value)) {
277
274
  return {
278
275
  isInt: {
279
276
  expected: 'A int value',
@@ -419,28 +416,37 @@ const RxapValidators = {
419
416
  * @deprecated removed use the rxapControlError or rxapControlErrors directive
420
417
  */
421
418
  class FormControlErrorDirective {
422
- constructor(template, parent, viewContainerRef) {
423
- this.template = template;
424
- this.parent = parent;
425
- this.viewContainerRef = viewContainerRef;
426
- }
427
- ngOnInit() {
428
- const control = this.parent.control?.get(this.name);
429
- if (!control) {
430
- throw new Error('Could not extract form control instance');
431
- }
432
- this.subscription = control.statusChanges.pipe(startWith(control.status), filter(status => status === 'INVALID'), tap(() => {
433
- this.viewContainerRef.clear();
434
- if (control.hasError(this.errorKey)) {
435
- this.viewContainerRef.createEmbeddedView(this.template, { $implicit: control.getError(this.errorKey) });
436
- }
437
- })).subscribe();
438
- }
439
- ngOnDestroy() {
440
- this.subscription?.unsubscribe();
419
+ constructor() {
420
+ this.template = inject(TemplateRef);
421
+ this.parent = inject(ControlContainer, { host: true, skipSelf: true });
422
+ this.viewContainerRef = inject(ViewContainerRef);
423
+ // eslint-disable-next-line @angular-eslint/no-input-rename
424
+ this.name = input.required({ ...(ngDevMode ? { debugName: "name" } : /* istanbul ignore next */ {}), alias: "rxapFormControlErrorFrom" });
425
+ // eslint-disable-next-line @angular-eslint/no-input-rename
426
+ this.errorKey = input.required({ ...(ngDevMode ? { debugName: "errorKey" } : /* istanbul ignore next */ {}), alias: "rxapFormControlErrorIf" });
427
+ effect((onCleanup) => {
428
+ const name = this.name();
429
+ const errorKey = this.errorKey();
430
+ untracked(() => {
431
+ const control = this.parent.control?.get(name);
432
+ if (!control) {
433
+ throw new Error('Could not extract form control instance');
434
+ }
435
+ const subscription = control.statusChanges.pipe(startWith(control.status), tap(() => {
436
+ this.viewContainerRef.clear();
437
+ if (control.hasError(errorKey)) {
438
+ this.viewContainerRef.createEmbeddedView(this.template, { $implicit: control.getError(errorKey) });
439
+ }
440
+ })).subscribe();
441
+ onCleanup(() => {
442
+ subscription.unsubscribe();
443
+ this.viewContainerRef.clear();
444
+ });
445
+ });
446
+ });
441
447
  }
442
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormControlErrorDirective, deps: [{ token: i0.TemplateRef }, { token: i1.ControlContainer, host: true, skipSelf: true }, { token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive }); }
443
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: FormControlErrorDirective, isStandalone: true, selector: "[rxapFormControlError]", inputs: { name: ["rxapFormControlErrorFrom", "name"], errorKey: ["rxapFormControlErrorIf", "errorKey"] }, ngImport: i0 }); }
448
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormControlErrorDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
449
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.9", type: FormControlErrorDirective, isStandalone: true, selector: "[rxapFormControlError]", inputs: { name: { classPropertyName: "name", publicName: "rxapFormControlErrorFrom", isSignal: true, isRequired: true, transformFunction: null }, errorKey: { classPropertyName: "errorKey", publicName: "rxapFormControlErrorIf", isSignal: true, isRequired: true, transformFunction: null } }, ngImport: i0 }); }
444
450
  }
445
451
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormControlErrorDirective, decorators: [{
446
452
  type: Directive,
@@ -448,27 +454,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImpor
448
454
  selector: '[rxapFormControlError]',
449
455
  standalone: true,
450
456
  }]
451
- }], ctorParameters: () => [{ type: i0.TemplateRef }, { type: i1.ControlContainer, decorators: [{
452
- type: Host
453
- }, {
454
- type: SkipSelf
455
- }] }, { type: i0.ViewContainerRef }], propDecorators: { name: [{
456
- type: Input,
457
- args: [{
458
- required: true,
459
- alias: 'rxapFormControlErrorFrom',
460
- }]
461
- }], errorKey: [{
462
- type: Input,
463
- args: [{
464
- required: true,
465
- alias: 'rxapFormControlErrorIf',
466
- }]
467
- }] } });
457
+ }], ctorParameters: () => [], propDecorators: { name: [{ type: i0.Input, args: [{ isSignal: true, alias: "rxapFormControlErrorFrom", required: true }] }], errorKey: [{ type: i0.Input, args: [{ isSignal: true, alias: "rxapFormControlErrorIf", required: true }] }] } });
468
458
 
469
459
  class FormControlMarkDirtyDirective {
470
- constructor(parent) {
471
- this.parent = parent;
460
+ constructor() {
461
+ this.parent = inject(ControlContainer);
472
462
  }
473
463
  onClick() {
474
464
  const control = this.parent.control;
@@ -479,23 +469,21 @@ class FormControlMarkDirtyDirective {
479
469
  control?.markAsDirty();
480
470
  }
481
471
  }
482
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormControlMarkDirtyDirective, deps: [{ token: i1.ControlContainer }], target: i0.ɵɵFactoryTarget.Directive }); }
472
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormControlMarkDirtyDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
483
473
  static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: FormControlMarkDirtyDirective, isStandalone: true, selector: "[rxapFormControlMarkDirty]", host: { listeners: { "click": "onClick()" } }, ngImport: i0 }); }
484
474
  }
485
475
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormControlMarkDirtyDirective, decorators: [{
486
476
  type: Directive,
487
477
  args: [{
488
478
  selector: '[rxapFormControlMarkDirty]',
479
+ host: { '(click)': 'onClick()' },
489
480
  standalone: true,
490
481
  }]
491
- }], ctorParameters: () => [{ type: i1.ControlContainer }], propDecorators: { onClick: [{
492
- type: HostListener,
493
- args: ['click']
494
- }] } });
482
+ }] });
495
483
 
496
484
  class FormControlMarkPristineDirective {
497
- constructor(parent) {
498
- this.parent = parent;
485
+ constructor() {
486
+ this.parent = inject(ControlContainer);
499
487
  }
500
488
  onClick() {
501
489
  const control = this.parent.control;
@@ -506,44 +494,40 @@ class FormControlMarkPristineDirective {
506
494
  control?.markAsPristine();
507
495
  }
508
496
  }
509
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormControlMarkPristineDirective, deps: [{ token: i1.ControlContainer }], target: i0.ɵɵFactoryTarget.Directive }); }
497
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormControlMarkPristineDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
510
498
  static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: FormControlMarkPristineDirective, isStandalone: true, selector: "[rxapFormControlMarkPristine]", host: { listeners: { "click": "onClick()" } }, ngImport: i0 }); }
511
499
  }
512
500
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormControlMarkPristineDirective, decorators: [{
513
501
  type: Directive,
514
502
  args: [{
515
503
  selector: '[rxapFormControlMarkPristine]',
504
+ host: { '(click)': 'onClick()' },
516
505
  standalone: true,
517
506
  }]
518
- }], ctorParameters: () => [{ type: i1.ControlContainer }], propDecorators: { onClick: [{
519
- type: HostListener,
520
- args: ['click']
521
- }] } });
507
+ }] });
522
508
 
523
509
  class FormControlMarkTouchedDirective {
524
- constructor(parent) {
525
- this.parent = parent;
510
+ constructor() {
511
+ this.parent = inject(ControlContainer);
526
512
  }
527
513
  onClick() {
528
514
  this.parent.control?.markAllAsTouched();
529
515
  }
530
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormControlMarkTouchedDirective, deps: [{ token: i1.ControlContainer }], target: i0.ɵɵFactoryTarget.Directive }); }
516
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormControlMarkTouchedDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
531
517
  static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: FormControlMarkTouchedDirective, isStandalone: true, selector: "[rxapFormControlMarkTouched]", host: { listeners: { "click": "onClick()" } }, ngImport: i0 }); }
532
518
  }
533
519
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormControlMarkTouchedDirective, decorators: [{
534
520
  type: Directive,
535
521
  args: [{
536
522
  selector: '[rxapFormControlMarkTouched]',
523
+ host: { '(click)': 'onClick()' },
537
524
  standalone: true,
538
525
  }]
539
- }], ctorParameters: () => [{ type: i1.ControlContainer }], propDecorators: { onClick: [{
540
- type: HostListener,
541
- args: ['click']
542
- }] } });
526
+ }] });
543
527
 
544
528
  class FormControlMarkUntouchedDirective {
545
- constructor(parent) {
546
- this.parent = parent;
529
+ constructor() {
530
+ this.parent = inject(ControlContainer);
547
531
  }
548
532
  onClick() {
549
533
  const control = this.parent.control;
@@ -554,19 +538,17 @@ class FormControlMarkUntouchedDirective {
554
538
  control?.markAsUntouched();
555
539
  }
556
540
  }
557
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormControlMarkUntouchedDirective, deps: [{ token: i1.ControlContainer }], target: i0.ɵɵFactoryTarget.Directive }); }
541
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormControlMarkUntouchedDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
558
542
  static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: FormControlMarkUntouchedDirective, isStandalone: true, selector: "[rxapFormControlMarkUntouched]", host: { listeners: { "click": "onClick()" } }, ngImport: i0 }); }
559
543
  }
560
544
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormControlMarkUntouchedDirective, decorators: [{
561
545
  type: Directive,
562
546
  args: [{
563
547
  selector: '[rxapFormControlMarkUntouched]',
548
+ host: { '(click)': 'onClick()' },
564
549
  standalone: true,
565
550
  }]
566
- }], ctorParameters: () => [{ type: i1.ControlContainer }], propDecorators: { onClick: [{
567
- type: HostListener,
568
- args: ['click']
569
- }] } });
551
+ }] });
570
552
 
571
553
  /**
572
554
  * A full exertion of FormControlName from @angular/forms. The only change is the
@@ -575,10 +557,14 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImpor
575
557
  * @deprecated use the ParentControlContainerDirective
576
558
  */
577
559
  class FormControlNameDirective extends FormControlName {
578
- constructor(parent, validators, asyncValidators, valueAccessors) {
560
+ constructor() {
561
+ const parent = inject(ControlContainer, { optional: true, skipSelf: true });
562
+ const validators = inject(NG_VALIDATORS, { optional: true, self: true }) ?? [];
563
+ const asyncValidators = inject(NG_ASYNC_VALIDATORS, { optional: true, self: true }) ?? [];
564
+ const valueAccessors = [...(inject(NG_VALUE_ACCESSOR, { optional: true, self: true }) ?? [])];
579
565
  super(parent, validators, asyncValidators, valueAccessors, null);
580
566
  }
581
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormControlNameDirective, deps: [{ token: i1.ControlContainer, optional: true, skipSelf: true }, { token: NG_VALIDATORS, optional: true, self: true }, { token: NG_ASYNC_VALIDATORS, optional: true, self: true }, { token: NG_VALUE_ACCESSOR, optional: true, self: true }], target: i0.ɵɵFactoryTarget.Directive }); }
567
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormControlNameDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
582
568
  static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: FormControlNameDirective, isStandalone: true, selector: "[rxapFormControlName]", inputs: { name: ["rxapFormControlName", "name"] }, providers: [
583
569
  {
584
570
  provide: NgControl,
@@ -596,38 +582,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImpor
596
582
  useExisting: forwardRef(() => FormControlNameDirective),
597
583
  },
598
584
  ],
585
+ // the base class declares the `name` input (alias formControlName); re-alias it to rxapFormControlName
586
+ // eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
587
+ inputs: [{ name: 'name', alias: 'rxapFormControlName' }],
599
588
  exportAs: 'rxapFormControl',
600
589
  standalone: true,
601
590
  }]
602
- }], ctorParameters: () => [{ type: i1.ControlContainer, decorators: [{
603
- type: Optional
604
- }, {
605
- type: SkipSelf
606
- }] }, { type: Array, decorators: [{
607
- type: Optional
608
- }, {
609
- type: Self
610
- }, {
611
- type: Inject,
612
- args: [NG_VALIDATORS]
613
- }] }, { type: Array, decorators: [{
614
- type: Optional
615
- }, {
616
- type: Self
617
- }, {
618
- type: Inject,
619
- args: [NG_ASYNC_VALIDATORS]
620
- }] }, { type: undefined, decorators: [{
621
- type: Optional
622
- }, {
623
- type: Self
624
- }, {
625
- type: Inject,
626
- args: [NG_VALUE_ACCESSOR]
627
- }] }], propDecorators: { name: [{
628
- type: Input,
629
- args: ['rxapFormControlName']
630
- }] } });
591
+ }], ctorParameters: () => [] });
631
592
 
632
593
  /**
633
594
  * A full exertion of FormGroupName from @angular/forms. The only change is the
@@ -640,10 +601,13 @@ class FormGroupNameDirective extends FormGroupName {
640
601
  // TODO : add type check
641
602
  return this.formDirective.getFormGroup(this);
642
603
  }
643
- constructor(parent, validators, asyncValidators) {
604
+ constructor() {
605
+ const parent = inject(ControlContainer, { optional: true, skipSelf: true });
606
+ const validators = [...(inject(NG_VALIDATORS, { optional: true, self: true }) ?? [])];
607
+ const asyncValidators = [...(inject(NG_ASYNC_VALIDATORS, { optional: true, self: true }) ?? [])];
644
608
  super(parent, validators, asyncValidators);
645
609
  }
646
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormGroupNameDirective, deps: [{ token: i1.ControlContainer, optional: true, skipSelf: true }, { token: NG_VALIDATORS, optional: true, self: true }, { token: NG_ASYNC_VALIDATORS, optional: true, self: true }], target: i0.ɵɵFactoryTarget.Directive }); }
610
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormGroupNameDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
647
611
  static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: FormGroupNameDirective, isStandalone: true, selector: "[rxapFormGroupName]", inputs: { name: ["rxapFormGroupName", "name"] }, providers: [
648
612
  {
649
613
  provide: ControlContainer,
@@ -661,31 +625,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImpor
661
625
  useExisting: forwardRef(() => FormGroupNameDirective),
662
626
  },
663
627
  ],
628
+ // the base class declares the `name` input (alias formGroupName); re-alias it to rxapFormGroupName
629
+ // eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
630
+ inputs: [{ name: 'name', alias: 'rxapFormGroupName' }],
664
631
  exportAs: 'rxapFormGroup',
665
632
  standalone: true,
666
633
  }]
667
- }], ctorParameters: () => [{ type: i1.ControlContainer, decorators: [{
668
- type: Optional
669
- }, {
670
- type: SkipSelf
671
- }] }, { type: undefined, decorators: [{
672
- type: Optional
673
- }, {
674
- type: Self
675
- }, {
676
- type: Inject,
677
- args: [NG_VALIDATORS]
678
- }] }, { type: undefined, decorators: [{
679
- type: Optional
680
- }, {
681
- type: Self
682
- }, {
683
- type: Inject,
684
- args: [NG_ASYNC_VALIDATORS]
685
- }] }], propDecorators: { name: [{
686
- type: Input,
687
- args: ['rxapFormGroupName']
688
- }] } });
634
+ }], ctorParameters: () => [] });
689
635
 
690
636
  const RXAP_FORM_INITIAL_STATE = new InjectionToken('rxap/forms/initial-state');
691
637
  const RXAP_FORM_CONTEXT = new InjectionToken('rxap/forms/context');
@@ -699,2240 +645,1974 @@ const RXAP_FORM_LOAD_METHOD = new InjectionToken('rxap/form/load-method');
699
645
  const RXAP_FORM_LOAD_FAILED_METHOD = new InjectionToken('rxap/form/load-failed-method');
700
646
  const RXAP_FORM_LOAD_SUCCESSFUL_METHOD = new InjectionToken('rxap/form/load-successful-method');
701
647
 
702
- var MetadataKeys;
703
- (function (MetadataKeys) {
704
- MetadataKeys["CONTROL_VALIDATORS"] = "rxap/forms/control-validators";
705
- MetadataKeys["CONTROL_ASYNC_VALIDATORS"] = "rxap/forms/control-async-validators";
706
- MetadataKeys["CONTROL_CHANGES"] = "rxap/forms/control-changes";
707
- MetadataKeys["CONTROL_SET_VALUE"] = "rxap/forms/control-set-value";
708
- MetadataKeys["FORM_ARRAY_GROUPS"] = "rxap/forms/form-array-groups";
709
- MetadataKeys["FORM_ARRAY_CONTROLS"] = "rxap/forms/form-array-controls";
710
- MetadataKeys["FORM_GROUPS"] = "rxap/forms/form-groups";
711
- MetadataKeys["FORM_CONTROLS"] = "rxap/forms/form-controls";
712
- })(MetadataKeys || (MetadataKeys = {}));
713
-
714
- function getControlValue(control) {
715
- if (control.getRawValue) {
716
- return control.getRawValue();
717
- }
718
- return control.value;
719
- }
720
- function controlValueChanges$(control) {
721
- return merge(defer(() => of(getControlValue(control))), control.valueChanges.pipe(map(() => getControlValue(control))));
722
- }
723
- function controlDisabled$(control) {
724
- return merge(defer(() => of(control.disabled)), merge(control.statusChanges, control.stateChanges?.asObservable() ?? EMPTY).pipe(map(() => control.disabled), distinctUntilChanged()));
725
- }
726
- function controlEnabled$(control) {
727
- return merge(defer(() => of(control.enabled)), merge(control.statusChanges, control.stateChanges?.asObservable() ?? EMPTY).pipe(map(() => control.enabled), distinctUntilChanged()));
728
- }
729
- function controlReadonly$(control) {
730
- return merge(defer(() => of(control.readonly ?? false)), merge(control.statusChanges, control.stateChanges?.asObservable() ?? EMPTY).pipe(map(() => control.readonly ?? false), distinctUntilChanged()));
731
- }
732
- function controlStatusChanges$(control) {
733
- return merge(defer(() => of(control.status)), control.statusChanges.pipe(map(() => control.status), distinctUntilChanged()));
734
- }
735
- function controlErrorChanges$(control) {
736
- return merge(defer(() => of(control.errors)), control.valueChanges.pipe(map(() => control.errors)), control.statusChanges.pipe(map(() => control.errors))).pipe(distinctUntilChanged((a, b) => equals(a, b)));
737
- }
738
- function enableControl(control, enabled, opts) {
739
- if (enabled) {
740
- control.enable(opts);
741
- }
742
- else {
743
- control.disable(opts);
744
- }
745
- }
746
- function disableControl(control, disabled, opts) {
747
- enableControl(control, !disabled, opts);
748
- }
749
- function controlDisabledWhile(control, observable, opts) {
750
- return observable.subscribe(isDisabled => disableControl(control, isDisabled, opts));
751
- }
752
- function controlEnabledWhile(control, observable, opts) {
753
- return observable.subscribe(isEnabled => enableControl(control, isEnabled, opts));
754
- }
755
- function mergeControlValidators(control, validators) {
756
- control.setValidators([...coerceArray(control.validator), ...coerceArray(validators)]);
757
- control.updateValueAndValidity();
758
- }
759
- function validateControlOn(control, validation) {
760
- return validation.subscribe(maybeError => {
761
- control.setErrors(maybeError);
762
- });
763
- }
764
- function hasErrorAndTouched(control, error, path) {
765
- const hasError = control.hasError(error, !path || path.length === 0 ? undefined : path);
766
- return hasError && control.touched;
767
- }
768
- function hasErrorAndDirty(control, error, path) {
769
- const hasError = control.hasError(error, !path || path.length === 0 ? undefined : path);
770
- return hasError && control.dirty;
771
- }
772
- function markAllDirty(control) {
773
- control.markAsDirty({ onlySelf: true });
774
- control._forEachChild((_control) => _control.markAllAsDirty());
775
- }
776
- function markAllPristine(control) {
777
- control.markAsPristine({ onlySelf: true });
778
- control._forEachChild((_control) => _control.markAllAsPristine());
779
- }
780
- function markAllUntouched(control) {
781
- control.markAsUntouched({ onlySelf: true });
782
- control._forEachChild((_control) => _control.markAllAsUntouched());
783
- }
784
- function selectControlValue$(control, mapFn) {
785
- return control.value$.pipe(map(mapFn), distinctUntilChanged());
786
- }
787
-
788
- class RxapFormArray extends UntypedFormArray {
789
- get readonly() {
790
- return this.parent?.readonly ?? this._readonly;
791
- }
792
- set readonly(value) {
793
- this._readonly = value;
794
- this.controls.forEach(control => control.stateChanges?.next());
795
- }
796
- /**
797
- * @internal
798
- */
799
- get rxapFormDefinition() {
800
- return this.parent.rxapFormDefinition;
648
+ class FormDirective extends FormGroupDirective {
649
+ get formDefinition() {
650
+ return this._formDefinition;
801
651
  }
802
- get controlPath() {
803
- const parent = this.parent;
804
- if (parent) {
805
- if (parent.controlPath) {
806
- if (parent === this.root) {
807
- return this.controlId;
808
- }
809
- else {
810
- return [parent.controlPath, this.controlId].join('.');
811
- }
652
+ constructor() {
653
+ super([], []);
654
+ /**
655
+ * @deprecated the directive does not rely on manual change detection anymore
656
+ */
657
+ this.cdr = inject(ChangeDetectorRef);
658
+ this.formDefinitionBuilder = inject(RXAP_FORM_DEFINITION_BUILDER, { skipSelf: true, optional: true }) ?? null;
659
+ this.loadingIndicatorService = inject(LoadingIndicatorService, { optional: true }) ?? null;
660
+ // skip self, bc the tokens are set to null in the providers of this directive
661
+ this.injectedSubmitMethod = inject(RXAP_FORM_SUBMIT_METHOD, { skipSelf: true, optional: true }) ?? null;
662
+ this.injectedLoadMethod = inject(RXAP_FORM_LOAD_METHOD, { skipSelf: true, optional: true }) ?? null;
663
+ this.injectedLoadFailedMethod = inject(RXAP_FORM_LOAD_FAILED_METHOD, { skipSelf: true, optional: true }) ?? null;
664
+ this.injectedLoadSuccessfulMethod = inject(RXAP_FORM_LOAD_SUCCESSFUL_METHOD, { skipSelf: true, optional: true }) ?? null;
665
+ this.injectedSubmitFailedMethod = inject(RXAP_FORM_SUBMIT_FAILED_METHOD, { skipSelf: true, optional: true }) ?? null;
666
+ this.injectedSubmitSuccessfulMethod = inject(RXAP_FORM_SUBMIT_SUCCESSFUL_METHOD, { skipSelf: true, optional: true }) ?? null;
667
+ this.injectedFormDefinition = inject(RXAP_FORM_DEFINITION, { optional: true }) ?? null;
668
+ this.injectedContext = inject(RXAP_FORM_CONTEXT, { optional: true }) ?? null;
669
+ this.injectedInitial = inject(RXAP_FORM_INITIAL_STATE, { optional: true }) ?? null;
670
+ this.initial = input(null, ...(ngDevMode ? [{ debugName: "initial" }] : /* istanbul ignore next */ []));
671
+ this.context = input(null, ...(ngDevMode ? [{ debugName: "context" }] : /* istanbul ignore next */ []));
672
+ /**
673
+ * The initial value: the input value or, as fallback, the value provided by the RXAP_FORM_INITIAL_STATE token
674
+ */
675
+ this.currentInitial = computed(() => {
676
+ const initial = this.initial();
677
+ if (initial) {
678
+ return initial;
812
679
  }
680
+ const injected = this.injectedInitial;
681
+ return injected && typeof injected === 'object' && !Array.isArray(injected) ? injected : null;
682
+ }, ...(ngDevMode ? [{ debugName: "currentInitial" }] : /* istanbul ignore next */ []));
683
+ /**
684
+ * The context: the input value or, as fallback, the value provided by the RXAP_FORM_CONTEXT token
685
+ */
686
+ this.currentContext = computed(() => this.context() ?? this.injectedContext, ...(ngDevMode ? [{ debugName: "currentContext" }] : /* istanbul ignore next */ []));
687
+ /**
688
+ * Emits when the submit method is executed without errors. The result of the
689
+ * submit method is passed as event object.
690
+ *
691
+ * If no submit method is defined then emit after the submit button
692
+ * is clicked.
693
+ */
694
+ this.rxapSubmit = output();
695
+ this.invalidSubmit = output();
696
+ this.submitSuccessful$ = output({ alias: 'submitSuccessful' });
697
+ this.submitting$ = new ToggleSubject();
698
+ this.submitError$ = new BehaviorSubject(null);
699
+ this.loading$ = new ToggleSubject();
700
+ this.loaded$ = new ToggleSubject();
701
+ this.loadingError$ = new BehaviorSubject(null);
702
+ this.submitting = toSignal(this.submitting$, { initialValue: false });
703
+ this.submitError = toSignal(this.submitError$, { initialValue: null });
704
+ this.loading = toSignal(this.loading$, { initialValue: false });
705
+ this.loaded = toSignal(this.loaded$, { initialValue: false });
706
+ this.loadingError = toSignal(this.loadingError$, { initialValue: null });
707
+ /**
708
+ * The form definition instance. Overrides the form definition provided by the
709
+ * RXAP_FORM_DEFINITION token or the RXAP_FORM_DEFINITION_BUILDER
710
+ */
711
+ this.useFormDefinition = input('', { ...(ngDevMode ? { debugName: "useFormDefinition" } : /* istanbul ignore next */ {}), alias: 'rxapForm' });
712
+ this.submitMethod = input(null, ...(ngDevMode ? [{ debugName: "submitMethod" }] : /* istanbul ignore next */ []));
713
+ this.loadMethod = input(null, ...(ngDevMode ? [{ debugName: "loadMethod" }] : /* istanbul ignore next */ []));
714
+ this.loadFailedMethod = input(null, ...(ngDevMode ? [{ debugName: "loadFailedMethod" }] : /* istanbul ignore next */ []));
715
+ this.loadSuccessfulMethod = input(null, ...(ngDevMode ? [{ debugName: "loadSuccessfulMethod" }] : /* istanbul ignore next */ []));
716
+ this.submitFailedMethod = input(null, ...(ngDevMode ? [{ debugName: "submitFailedMethod" }] : /* istanbul ignore next */ []));
717
+ this.submitSuccessfulMethod = input(null, ...(ngDevMode ? [{ debugName: "submitSuccessfulMethod" }] : /* istanbul ignore next */ []));
718
+ // the input value has precedence over the value provided by the injection token
719
+ this.currentSubmitMethod = computed(() => this.submitMethod() ?? this.injectedSubmitMethod, ...(ngDevMode ? [{ debugName: "currentSubmitMethod" }] : /* istanbul ignore next */ []));
720
+ this.currentLoadMethod = computed(() => this.loadMethod() ?? this.injectedLoadMethod, ...(ngDevMode ? [{ debugName: "currentLoadMethod" }] : /* istanbul ignore next */ []));
721
+ this.currentLoadFailedMethod = computed(() => this.loadFailedMethod() ?? this.injectedLoadFailedMethod, ...(ngDevMode ? [{ debugName: "currentLoadFailedMethod" }] : /* istanbul ignore next */ []));
722
+ this.currentLoadSuccessfulMethod = computed(() => this.loadSuccessfulMethod() ?? this.injectedLoadSuccessfulMethod, ...(ngDevMode ? [{ debugName: "currentLoadSuccessfulMethod" }] : /* istanbul ignore next */ []));
723
+ this.currentSubmitFailedMethod = computed(() => this.submitFailedMethod() ?? this.injectedSubmitFailedMethod, ...(ngDevMode ? [{ debugName: "currentSubmitFailedMethod" }] : /* istanbul ignore next */ []));
724
+ this.currentSubmitSuccessfulMethod = computed(() => this.submitSuccessfulMethod() ?? this.injectedSubmitSuccessfulMethod, ...(ngDevMode ? [{ debugName: "currentSubmitSuccessfulMethod" }] : /* istanbul ignore next */ []));
725
+ this._autoSubmitSubscription = new Subscription();
726
+ let formDefinition = this.injectedFormDefinition;
727
+ if (!formDefinition && this.formDefinitionBuilder) {
728
+ formDefinition = this.formDefinitionBuilder.build();
813
729
  }
814
- return this.controlId;
815
- }
816
- get fullControlPath() {
817
- const parent = this.parent;
818
- if (parent) {
819
- if (parent.fullControlPath) {
820
- return [parent.fullControlPath, this.controlId].join('.');
821
- }
730
+ if (formDefinition) {
731
+ this._formDefinition = formDefinition;
732
+ this.form = formDefinition.rxapFormGroup;
822
733
  }
823
- return this.controlId;
824
- }
825
- constructor(controls, options) {
826
- super(controls, options);
827
- this.controls = controls;
828
- this._readonly = false;
829
- this.value$ = controlValueChanges$(this);
830
- this.disabled$ = controlDisabled$(this);
831
- this.enabled$ = controlEnabled$(this);
832
- this.status$ = controlStatusChanges$(this);
833
- this.errors$ = controlErrorChanges$(this);
834
- this.touchChanges = new Subject();
835
- this.touch$ = this.touchChanges
836
- .asObservable()
837
- .pipe(distinctUntilChanged());
838
- this.dirtyChanges = new Subject();
839
- this.dirty$ = this.dirtyChanges
840
- .asObservable()
841
- .pipe(distinctUntilChanged());
842
- this.controlId = options.controlId;
843
- this._builder = options.builder;
844
- this._controlInsertedFn = options.controlInsertedFn;
845
- this._controlRemovedFn = options.controlRemovedFn;
846
- }
847
- select(mapFn) {
848
- return this.value$.pipe(map(mapFn), distinctUntilChanged());
849
- }
850
- at(index) {
851
- return super.at(index);
734
+ this.loadingIndicatorService?.attachLoading(this.loading$);
735
+ this.loadingIndicatorService?.attachLoading(this.submitting$);
852
736
  }
853
- getRawValue() {
854
- return super.getRawValue();
737
+ /**
738
+ * Applies the form definition passed with the rxapForm input
739
+ */
740
+ applyFormDefinitionInput() {
741
+ const value = this.useFormDefinition();
742
+ if (value) {
743
+ this._formDefinition = value;
744
+ this.form = value.rxapFormGroup;
745
+ }
855
746
  }
856
- insert(index, control) {
857
- if (isDevMode()) {
858
- console.warn('It is not recommend to use the FormArray.insert method');
747
+ ngOnChanges(changes) {
748
+ // the form must be set before the FormGroupDirective validates its presence
749
+ this.applyFormDefinitionInput();
750
+ super.ngOnChanges(changes);
751
+ const formChange = changes['form'];
752
+ if (formChange && !formChange.firstChange) {
753
+ this.loadInitialState(formChange.currentValue);
859
754
  }
860
- return super.insert(index, control);
861
755
  }
862
- /**
863
- * inserts a new control at the specified index. If the index is undefined
864
- * the new control will be added to the end.
865
- *
866
- * @param index (optional) the index where the control should be created
867
- * @param state (optional) the initial state of the new control
868
- * @param options (optional) ControlEventOptions
869
- */
870
- insertAt(index, state, options) {
871
- const insertIndex = index ?? this.controls.length;
872
- const length = this.controls.length;
873
- const controlOrDefinition = this._builder(state, {
874
- controlId: insertIndex.toFixed(0),
875
- });
876
- this._controlInsertedFn(insertIndex, controlOrDefinition);
877
- if (insertIndex < this.controls.length) {
878
- // update the control ids for all controls, that are moved.
879
- for (let i = insertIndex; i < this.controls.length; i++) {
880
- Reflect.set(this.controls[i], 'controlId', (i + 1).toFixed(0));
881
- }
756
+ ngOnInit() {
757
+ this.applyFormDefinitionInput();
758
+ if (!this._formDefinition) {
759
+ // TODO : replace with rxap error
760
+ throw new Error('The form definition instance is not defined');
882
761
  }
883
- if (length === this.controls.length) {
884
- // the _controlInsertedFn has not yet added the new control to the form array
885
- // call the super insert after the update, bc the insert method will
886
- // trigger a change detection
887
- if (controlOrDefinition instanceof AbstractControl) {
888
- super.insert(insertIndex, controlOrDefinition, options);
889
- }
890
- else {
891
- super.insert(insertIndex, controlOrDefinition.rxapFormGroup, options);
892
- }
762
+ if (!this.form) {
763
+ // TODO : replace with rxap error
764
+ throw new Error('The form instance is not defined');
893
765
  }
894
- else {
895
- if (controlOrDefinition instanceof AbstractControl) {
896
- controlOrDefinition.setParent(this);
897
- controlOrDefinition['_registerOnCollectionChange']?.(this['_onCollectionChange']);
898
- }
899
- else {
900
- controlOrDefinition.rxapFormGroup.setParent(this);
901
- controlOrDefinition.rxapFormGroup['_registerOnCollectionChange']?.(this['_onCollectionChange']);
902
- }
903
- this.updateValueAndValidity({ emitEvent: options?.emitEvent });
766
+ this.loadInitialState(this.form);
767
+ function HasNgOnInitMethod(obj) {
768
+ return obj && typeof obj.ngOnInit === 'function';
904
769
  }
905
- }
906
- disabledWhile(observable, options) {
907
- return controlDisabledWhile(this, observable, options);
908
- }
909
- enabledWhile(observable, options) {
910
- return controlEnabledWhile(this, observable, options);
911
- }
912
- mergeValidators(validators) {
913
- mergeControlValidators(this, validators);
914
- }
915
- mergeAsyncValidators(validators) {
916
- this.setAsyncValidators([
917
- ...coerceArray(this.asyncValidator),
918
- ...coerceArray(validators),
919
- ]);
920
- this.updateValueAndValidity();
921
- }
922
- markAllAsDirty() {
923
- markAllDirty(this);
924
- }
925
- markAllAsPristine() {
926
- markAllPristine(this);
927
- }
928
- setValue(valueOrObservable, options) {
929
- if (isObservable(valueOrObservable)) {
930
- return valueOrObservable.subscribe((value) => {
931
- super.setValue(value, options);
932
- });
770
+ if (HasNgOnInitMethod(this._formDefinition)) {
771
+ this._formDefinition.ngOnInit();
772
+ }
773
+ if (this._formDefinition.rxapMetadata.autoSubmit) {
774
+ const debounce = typeof this._formDefinition.rxapMetadata.autoSubmit === 'number'
775
+ ? this._formDefinition.rxapMetadata.autoSubmit
776
+ : 5000;
777
+ this._autoSubmitSubscription = this
778
+ .form
779
+ .valueChanges
780
+ .pipe(debounceTime(debounce), filter(() => this.form.valid), tap((value) => {
781
+ if (isDevMode()) {
782
+ console.debug(`Auto submit form '${this._formDefinition.rxapMetadata.id}'`, value);
783
+ }
784
+ }), tap(() => this.submit()))
785
+ .subscribe();
933
786
  }
934
- super.setValue(valueOrObservable, options);
935
- }
936
- markAllAsUntouched() {
937
- markAllUntouched(this);
938
- }
939
- validateOn(observableValidation) {
940
- return observableValidation.subscribe((maybeError) => {
941
- this.setErrors(maybeError);
942
- });
943
- }
944
- hasErrorAndTouched(errorCode, path) {
945
- return hasErrorAndTouched(this, errorCode, path);
946
787
  }
947
- _patchValue(value, options) {
948
- // Even though the `value` argument type doesn't allow `null` and `undefined` values, the
949
- // `patchValue` can be called recursively and inner data structures might have these values, so
950
- // we just ignore such cases when a field containing FormArray instance receives `null` or
951
- // `undefined` as a value.
952
- if (value == null /* both `null` and `undefined` */) {
953
- return;
788
+ onSubmit($event) {
789
+ $event.preventDefault();
790
+ super.onSubmit($event);
791
+ if (this.form.valid) {
792
+ this.submit();
954
793
  }
955
- if (options?.strict) {
956
- if (this.length > value.length) {
957
- for (let index = this.length - 1; index >= value.length; index--) {
958
- this.removeAt(index);
794
+ else {
795
+ // eslint-disable-next-line no-inner-declarations
796
+ function reduceErrors(control, errors = {}) {
797
+ if (control.invalid) {
798
+ if (control.controls) {
799
+ if (Array.isArray(control.controls)) {
800
+ const errorList = [];
801
+ for (const item of control.controls) {
802
+ errorList.push(reduceErrors(item));
803
+ }
804
+ errors[control.controlId] = errorList;
805
+ }
806
+ else {
807
+ const innerErrors = {};
808
+ for (const child of Object.values(control.controls)) {
809
+ reduceErrors(child, innerErrors);
810
+ }
811
+ errors[control.controlId] = innerErrors;
812
+ }
813
+ }
814
+ else {
815
+ if (control.errors) {
816
+ errors[control.controlId] = control.errors;
817
+ }
818
+ }
959
819
  }
820
+ return errors;
960
821
  }
961
- }
962
- value.forEach((newValue, index) => {
963
- if (this.at(index)) {
964
- this.at(index)
965
- .patchValue(newValue, {
966
- ...(options ?? {}),
967
- onlySelf: true,
968
- });
969
- }
970
- else if (options?.coerce) {
971
- this.insertAt(index, value[index]);
822
+ if (isDevMode()) {
823
+ console.log('Form submit is not valid for: ' + this.form.controlId, this.form.errors);
824
+ // eslint-disable-next-line no-inner-declarations
825
+ function printErrorControls(control) {
826
+ if (!control.valid) {
827
+ console.group(control.controlId);
828
+ if (control.controls) {
829
+ if (Array.isArray(control.controls)) {
830
+ for (let i = 0; i < control.controls.length; i++) {
831
+ const child = control.controls[i];
832
+ if (!child.valid) {
833
+ console.group(`index: ${i}`);
834
+ printErrorControls(child);
835
+ console.groupEnd();
836
+ }
837
+ }
838
+ }
839
+ else {
840
+ for (const child of Object.values(control.controls)) {
841
+ printErrorControls(child);
842
+ }
843
+ }
844
+ }
845
+ else {
846
+ if (control.errors) {
847
+ for (const [key, value] of Object.entries(control.errors)) {
848
+ console.group(key);
849
+ console.log(value);
850
+ console.groupEnd();
851
+ }
852
+ }
853
+ console.log('value: ', control.value);
854
+ }
855
+ console.groupEnd();
856
+ }
857
+ }
858
+ printErrorControls(this.form);
972
859
  }
973
- });
974
- this.updateValueAndValidity(options);
975
- }
976
- patchValue(valueOrObservable, options) {
977
- if (isObservable(valueOrObservable)) {
978
- return valueOrObservable.subscribe((value) => {
979
- this._patchValue(value, options);
980
- });
860
+ this.invalidSubmit.emit(reduceErrors(this.form));
981
861
  }
982
- this._patchValue(valueOrObservable, options);
983
- }
984
- hasErrorAndDirty(errorCode, path) {
985
- return hasErrorAndDirty(this, errorCode, path);
862
+ return false;
986
863
  }
987
- removeAt(index, opts) {
988
- if (isDevMode()) {
989
- console.warn('It is not recommend to use the FormArray.removeAt method');
990
- }
991
- const length = this.controls.length;
992
- this._controlRemovedFn(index);
993
- if (length === this.controls.length) {
994
- super.removeAt(index);
864
+ loadInitialState(form) {
865
+ const initial = this.currentInitial();
866
+ if (initial) {
867
+ if (isDevMode()) {
868
+ console.log('use the value from input initial');
869
+ }
870
+ form.patchValue(initial, { setInitialValue: true });
995
871
  }
996
872
  else {
997
- this.updateValueAndValidity({ emitEvent: opts?.emitEvent });
873
+ const loadMethod = this.currentLoadMethod();
874
+ if (loadMethod) {
875
+ this.loading$.enable();
876
+ try {
877
+ const resultOrPromise = loadMethod.call({ context: this.currentContext(), initial: this.currentInitial() });
878
+ if (isPromise(resultOrPromise)) {
879
+ resultOrPromise
880
+ .then((value) => {
881
+ form.patchValue(value, { setInitialValue: true });
882
+ this.loaded$.enable();
883
+ this.loadSuccessful(value);
884
+ })
885
+ .catch((error) => {
886
+ this.loadingError$.next(error);
887
+ this.loadFailed(error);
888
+ })
889
+ .finally(() => {
890
+ this.loading$.disable();
891
+ });
892
+ }
893
+ else if (isObject(resultOrPromise)) {
894
+ form.patchValue(resultOrPromise, { setInitialValue: true });
895
+ this.loaded$.enable();
896
+ this.loadSuccessful(resultOrPromise);
897
+ this.loading$.disable();
898
+ }
899
+ }
900
+ catch (error) {
901
+ this.loaded$.disable();
902
+ this.loadingError$.next(error);
903
+ this.loadFailed(error);
904
+ this.loading$.disable();
905
+ }
906
+ }
907
+ else {
908
+ if (isDevMode()) {
909
+ console.warn('The form loading method is not defined for: ' + this.form.controlId);
910
+ }
911
+ this.loaded$.enable();
912
+ }
998
913
  }
999
914
  }
1000
- setEnable(enable = true, opts) {
1001
- enableControl(this, enable, opts);
1002
- }
1003
- push(control, options) {
1004
- if (isDevMode()) {
1005
- console.warn('It is not recommend to use the FormArray.push method');
915
+ loadSuccessful(value) {
916
+ const loadSuccessfulMethod = this.currentLoadSuccessfulMethod();
917
+ if (loadSuccessfulMethod) {
918
+ loadSuccessfulMethod.call(value);
1006
919
  }
1007
- return super.push(control, options);
1008
- }
1009
- setDisable(disable = true, opts) {
1010
- disableControl(this, disable, opts);
1011
- }
1012
- setControl(index, control, options) {
1013
- if (isDevMode()) {
1014
- console.warn('It is not recommend to use the FormArray.setControl method');
920
+ else if (isDevMode()) {
921
+ console.warn('The load successful is not defined for: ' + this.form.controlId);
1015
922
  }
1016
- return super.setControl(index, control, options);
1017
- }
1018
- markAsTouched(opts) {
1019
- super.markAsTouched(opts);
1020
- this.touchChanges.next(true);
1021
923
  }
1022
- markAsUntouched(opts) {
1023
- super.markAsUntouched(opts);
1024
- this.touchChanges.next(false);
924
+ loadFailed(error) {
925
+ console.debug('Load Error:', error);
926
+ console.error('Load Error:', error.message);
927
+ const loadFailedMethod = this.currentLoadFailedMethod();
928
+ if (loadFailedMethod) {
929
+ loadFailedMethod?.call(error);
930
+ }
931
+ else if (isDevMode()) {
932
+ console.warn('The form loading failed for: ' + this.form.controlId);
933
+ }
1025
934
  }
1026
- markAsPristine(opts) {
1027
- super.markAsPristine(opts);
1028
- this.dirtyChanges.next(false);
1029
- }
1030
- markAsDirty(opts) {
1031
- super.markAsDirty(opts);
1032
- this.dirtyChanges.next(true);
1033
- }
1034
- reset(value, options) {
1035
- super.reset(value, options);
1036
- }
1037
- setValidators(newValidator, updateValueAndValidity = true) {
1038
- super.setValidators(newValidator);
1039
- if (updateValueAndValidity) {
1040
- super.updateValueAndValidity();
1041
- }
1042
- }
1043
- setAsyncValidators(newValidator, updateValueAndValidity = true) {
1044
- super.setAsyncValidators(newValidator);
1045
- if (updateValueAndValidity) {
1046
- super.updateValueAndValidity();
1047
- }
1048
- }
1049
- hasError(errorCode, path) {
1050
- return super.hasError(errorCode, path);
1051
- }
1052
- setErrors(errors, opts = {}) {
1053
- return super.setErrors(errors, opts);
1054
- }
1055
- getError(errorCode, path) {
1056
- return super.getError(errorCode, path);
1057
- }
1058
- }
1059
-
1060
- class RxapFormGroup extends UntypedFormGroup {
1061
- /**
1062
- * @internal
1063
- */
1064
- get rxapFormDefinition() {
1065
- if (!this.parent) {
1066
- return this._rxapFormDefinition;
935
+ getSubmitValue() {
936
+ let value = undefined;
937
+ if (typeof this._formDefinition['getSubmitValue'] === 'function') {
938
+ value = this._formDefinition.getSubmitValue();
1067
939
  }
1068
- if (this._rxapFormDefinition) {
1069
- return this._rxapFormDefinition;
940
+ else if (typeof this._formDefinition['toJSON'] === 'function') {
941
+ value = this._formDefinition.toJSON();
1070
942
  }
1071
- return this.parent.rxapFormDefinition;
1072
- }
1073
- get readonly() {
1074
- return this.parent?.readonly ?? this._readonly;
1075
- }
1076
- set readonly(value) {
1077
- this._readonly = value;
1078
- Object.values(this.controls ?? {}).forEach(control => control.stateChanges?.next());
943
+ value = value ?? clone(this.form.value);
944
+ return value;
1079
945
  }
1080
- get controlPath() {
1081
- const parent = this.parent;
1082
- if (parent) {
1083
- if (parent.controlPath) {
1084
- if (parent === this.root) {
1085
- return this.controlId;
946
+ submit() {
947
+ const value = this.getSubmitValue();
948
+ const submitMethod = this.currentSubmitMethod();
949
+ if (submitMethod) {
950
+ Reflect.set(this, 'submitted', false);
951
+ this.submitting$.enable();
952
+ this.submitError$.next(null);
953
+ try {
954
+ const resultOrPromise = submitMethod.call(value, this.currentContext(), this.currentInitial());
955
+ if (isPromise(resultOrPromise)) {
956
+ resultOrPromise
957
+ .then((result) => {
958
+ Reflect.set(this, 'submitted', true);
959
+ this.rxapSubmit.emit(result);
960
+ this.submitSuccessful(result);
961
+ })
962
+ .catch((error) => {
963
+ this.submitError$.next(error);
964
+ this.submitFailed(error);
965
+ })
966
+ .finally(() => {
967
+ this.submitting$.disable();
968
+ });
1086
969
  }
1087
970
  else {
1088
- return [parent.controlPath, this.controlId].join('.');
971
+ Reflect.set(this, 'submitted', true);
972
+ this.rxapSubmit.emit(resultOrPromise);
973
+ this.submitSuccessful(resultOrPromise);
974
+ this.submitting$.disable();
1089
975
  }
1090
976
  }
977
+ catch (error) {
978
+ this.submitting$.disable();
979
+ this.submitError$.next(error);
980
+ this.submitFailed(error);
981
+ }
1091
982
  }
1092
- return '';
1093
- }
1094
- get fullControlPath() {
1095
- const parent = this.parent;
1096
- if (parent) {
1097
- if (parent.fullControlPath) {
1098
- return [parent.fullControlPath, this.controlId].join('.');
983
+ else {
984
+ if (isDevMode()) {
985
+ console.warn('The form submit method is not defined for: ' + this.form.controlId);
1099
986
  }
987
+ this.rxapSubmit.emit(value);
988
+ this.submitSuccessful(value);
1100
989
  }
1101
- return this.controlId;
1102
- }
1103
- constructor(controls, options) {
1104
- super(controls, options);
1105
- this.controls = controls;
1106
- this._readonly = false;
1107
- this.touchChanges = new Subject();
1108
- this.dirtyChanges = new Subject();
1109
- this.touch$ = this.touchChanges.asObservable().pipe(distinctUntilChanged());
1110
- this.dirty$ = this.dirtyChanges.asObservable().pipe(distinctUntilChanged());
1111
- this.value$ = controlValueChanges$(this);
1112
- this.disabled$ = controlDisabled$(this);
1113
- this.enabled$ = controlEnabled$(this);
1114
- this.status$ = controlStatusChanges$(this);
1115
- this.errors$ = controlErrorChanges$(this);
1116
- this.controlId = options.controlId;
1117
- }
1118
- select(mapFn) {
1119
- return selectControlValue$(this, mapFn);
1120
- }
1121
- getRawValue() {
1122
- return super.getRawValue();
1123
- }
1124
- get(path) {
1125
- return super.get(path);
1126
- }
1127
- getControl(...names) {
1128
- return this.get(names.join('.'));
1129
- }
1130
- addControl(name, control) {
1131
- super.addControl(name, control);
1132
- }
1133
- removeControl(name) {
1134
- super.removeControl(name);
1135
- }
1136
- contains(controlName) {
1137
- return super.contains(controlName);
1138
990
  }
1139
- setControl(name, control) {
1140
- super.setControl(name, control);
1141
- }
1142
- setValue(valueOrObservable, options) {
1143
- if (isObservable(valueOrObservable)) {
1144
- return valueOrObservable.subscribe((value) =>
1145
- // TODO : refactor RxapFormGroup to typed FormGroup
1146
- super.setValue(value, options));
991
+ submitFailed(error) {
992
+ console.debug('Submit Error:', error);
993
+ console.error('Submit Error:', error.message);
994
+ const submitFailedMethod = this.currentSubmitFailedMethod();
995
+ if (submitFailedMethod) {
996
+ submitFailedMethod.call(error);
1147
997
  }
1148
- super.setValue(valueOrObservable, options);
1149
- }
1150
- _patchValue(value, options) {
1151
- // Even though the `value` argument type doesn't allow `null` and `undefined` values, the
1152
- // `patchValue` can be called recursively and inner data structures might have these values, so
1153
- // we just ignore such cases when a field containing FormGroup instance receives `null` or
1154
- // `undefined` as a value.
1155
- if (value == null /* both `null` and `undefined` */) {
1156
- return;
998
+ else if (isDevMode()) {
999
+ console.warn('The form submit failed method is not defined for: ' +
1000
+ this.form.controlId);
1157
1001
  }
1158
- Object.keys(value).forEach(name => {
1159
- // TODO : resolve type issue
1160
- const controls = this.controls;
1161
- if (controls[name]) {
1162
- controls[name].patchValue(value[name], {
1163
- ...(options ?? {}),
1164
- onlySelf: true,
1165
- });
1166
- }
1167
- });
1168
- this.updateValueAndValidity(options);
1169
1002
  }
1170
- patchValue(valueOrObservable, options) {
1171
- if (isObservable(valueOrObservable)) {
1172
- return valueOrObservable.subscribe((value) =>
1173
- // TODO : refactor RxapFormGroup to typed FormGroup
1174
- super.patchValue(value, options));
1003
+ submitSuccessful(value) {
1004
+ this.submitSuccessful$.emit(value);
1005
+ const submitSuccessfulMethod = this.currentSubmitSuccessfulMethod();
1006
+ if (submitSuccessfulMethod) {
1007
+ submitSuccessfulMethod.call(value);
1175
1008
  }
1176
- this._patchValue(valueOrObservable, options);
1177
- }
1178
- disabledWhile(observable, options) {
1179
- return controlDisabledWhile(this, observable, options);
1180
- }
1181
- enabledWhile(observable, options) {
1182
- return controlEnabledWhile(this, observable, options);
1183
- }
1184
- mergeValidators(validators) {
1185
- mergeControlValidators(this, validators);
1186
- }
1187
- mergeAsyncValidators(validators) {
1188
- this.setAsyncValidators([
1189
- ...coerceArray(this.asyncValidator),
1190
- ...coerceArray(validators),
1191
- ]);
1192
- this.updateValueAndValidity();
1193
- }
1194
- markAsTouched(opts) {
1195
- super.markAsTouched(opts);
1196
- this.touchChanges.next(true);
1197
- }
1198
- markAsUntouched(opts) {
1199
- super.markAsUntouched(opts);
1200
- this.touchChanges.next(false);
1201
- }
1202
- markAsPristine(opts) {
1203
- super.markAsPristine(opts);
1204
- this.dirtyChanges.next(false);
1205
- }
1206
- markAsDirty(opts) {
1207
- super.markAsDirty(opts);
1208
- this.dirtyChanges.next(true);
1209
- }
1210
- markAllAsDirty() {
1211
- markAllDirty(this);
1212
- }
1213
- markAllAsPristine() {
1214
- markAllPristine(this);
1215
- }
1216
- markAllAsUntouched() {
1217
- markAllUntouched(this);
1218
- }
1219
- reset(formState, options) {
1220
- super.reset(formState, options);
1221
- }
1222
- setValidators(newValidator, updateValueAndValidity = true) {
1223
- super.setValidators(newValidator);
1224
- if (updateValueAndValidity) {
1225
- super.updateValueAndValidity();
1009
+ else if (isDevMode()) {
1010
+ console.warn('The form submit successful method is not defined for: ' +
1011
+ this.form.controlId);
1226
1012
  }
1227
1013
  }
1228
- setAsyncValidators(newValidator, updateValueAndValidity = true) {
1229
- super.setAsyncValidators(newValidator);
1230
- if (updateValueAndValidity) {
1231
- super.updateValueAndValidity();
1014
+ ngOnDestroy() {
1015
+ super.ngOnDestroy();
1016
+ this._autoSubmitSubscription?.unsubscribe();
1017
+ function HasNgOnDestroyMethod(obj) {
1018
+ return obj && typeof obj.ngOnDestroy === 'function';
1019
+ }
1020
+ if (HasNgOnDestroyMethod(this._formDefinition)) {
1021
+ this._formDefinition.ngOnDestroy();
1232
1022
  }
1233
1023
  }
1234
- validateOn(observableValidation) {
1235
- return validateControlOn(this, observableValidation);
1236
- }
1237
- hasError(errorCode, path) {
1238
- return super.hasError(errorCode, path);
1239
- }
1240
- setErrors(errors, opts = {}) {
1241
- return super.setErrors(errors, opts);
1242
- }
1243
- getError(errorCode, path) {
1244
- return super.getError(errorCode, path);
1024
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
1025
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.9", type: FormDirective, isStandalone: true, selector: "form[rxapForm]:not([formGroup]):not([ngForm]),rxap-form,form[rxapForm]", inputs: { initial: { classPropertyName: "initial", publicName: "initial", isSignal: true, isRequired: false, transformFunction: null }, context: { classPropertyName: "context", publicName: "context", isSignal: true, isRequired: false, transformFunction: null }, useFormDefinition: { classPropertyName: "useFormDefinition", publicName: "rxapForm", isSignal: true, isRequired: false, transformFunction: null }, submitMethod: { classPropertyName: "submitMethod", publicName: "submitMethod", isSignal: true, isRequired: false, transformFunction: null }, loadMethod: { classPropertyName: "loadMethod", publicName: "loadMethod", isSignal: true, isRequired: false, transformFunction: null }, loadFailedMethod: { classPropertyName: "loadFailedMethod", publicName: "loadFailedMethod", isSignal: true, isRequired: false, transformFunction: null }, loadSuccessfulMethod: { classPropertyName: "loadSuccessfulMethod", publicName: "loadSuccessfulMethod", isSignal: true, isRequired: false, transformFunction: null }, submitFailedMethod: { classPropertyName: "submitFailedMethod", publicName: "submitFailedMethod", isSignal: true, isRequired: false, transformFunction: null }, submitSuccessfulMethod: { classPropertyName: "submitSuccessfulMethod", publicName: "submitSuccessfulMethod", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { ngSubmit: "ngSubmit", rxapSubmit: "rxapSubmit", invalidSubmit: "invalidSubmit", submitSuccessful$: "submitSuccessful" }, host: { listeners: { "reset": "onReset()" }, properties: { "class.rxap-submitting": "submitting()", "class.rxap-submit-error": "!!submitError()", "class.rxap-loading": "loading()", "class.rxap-loaded": "loaded()", "class.rxap-loading-error": "!!loadingError()" } }, providers: [
1026
+ {
1027
+ provide: ControlContainer,
1028
+ // ignore coverage
1029
+ useExisting: forwardRef(() => FormDirective),
1030
+ },
1031
+ // region form provider clear
1032
+ // form provider that are directly associated with the current form
1033
+ // are cleared to prevent that inner forms can access this providers
1034
+ // Example: The parent form has a submit method provider and the inner should
1035
+ // not have a submit method provider. If the parent submit method provider is
1036
+ // not cleared then the inner form uses the parent submit method provider on
1037
+ // submit
1038
+ {
1039
+ provide: RXAP_FORM_SUBMIT_METHOD,
1040
+ useValue: null,
1041
+ },
1042
+ {
1043
+ provide: RXAP_FORM_LOAD_METHOD,
1044
+ useValue: null,
1045
+ },
1046
+ {
1047
+ provide: RXAP_FORM_LOAD_FAILED_METHOD,
1048
+ useValue: null,
1049
+ },
1050
+ {
1051
+ provide: RXAP_FORM_LOAD_SUCCESSFUL_METHOD,
1052
+ useValue: null,
1053
+ },
1054
+ {
1055
+ provide: RXAP_FORM_SUBMIT_FAILED_METHOD,
1056
+ useValue: null,
1057
+ },
1058
+ {
1059
+ provide: RXAP_FORM_SUBMIT_SUCCESSFUL_METHOD,
1060
+ useValue: null,
1061
+ },
1062
+ {
1063
+ provide: RXAP_FORM_DEFINITION_BUILDER,
1064
+ useValue: null,
1065
+ },
1066
+ // endregion
1067
+ ], exportAs: ["rxapForm"], usesInheritance: true, usesOnChanges: true, ngImport: i0 }); }
1068
+ }
1069
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormDirective, decorators: [{
1070
+ type: Directive,
1071
+ args: [{
1072
+ selector: 'form[rxapForm]:not([formGroup]):not([ngForm]),rxap-form,form[rxapForm]',
1073
+ providers: [
1074
+ {
1075
+ provide: ControlContainer,
1076
+ // ignore coverage
1077
+ useExisting: forwardRef(() => FormDirective),
1078
+ },
1079
+ // region form provider clear
1080
+ // form provider that are directly associated with the current form
1081
+ // are cleared to prevent that inner forms can access this providers
1082
+ // Example: The parent form has a submit method provider and the inner should
1083
+ // not have a submit method provider. If the parent submit method provider is
1084
+ // not cleared then the inner form uses the parent submit method provider on
1085
+ // submit
1086
+ {
1087
+ provide: RXAP_FORM_SUBMIT_METHOD,
1088
+ useValue: null,
1089
+ },
1090
+ {
1091
+ provide: RXAP_FORM_LOAD_METHOD,
1092
+ useValue: null,
1093
+ },
1094
+ {
1095
+ provide: RXAP_FORM_LOAD_FAILED_METHOD,
1096
+ useValue: null,
1097
+ },
1098
+ {
1099
+ provide: RXAP_FORM_LOAD_SUCCESSFUL_METHOD,
1100
+ useValue: null,
1101
+ },
1102
+ {
1103
+ provide: RXAP_FORM_SUBMIT_FAILED_METHOD,
1104
+ useValue: null,
1105
+ },
1106
+ {
1107
+ provide: RXAP_FORM_SUBMIT_SUCCESSFUL_METHOD,
1108
+ useValue: null,
1109
+ },
1110
+ {
1111
+ provide: RXAP_FORM_DEFINITION_BUILDER,
1112
+ useValue: null,
1113
+ },
1114
+ // endregion
1115
+ ],
1116
+ host: {
1117
+ '(reset)': 'onReset()',
1118
+ '[class.rxap-submitting]': 'submitting()',
1119
+ '[class.rxap-submit-error]': '!!submitError()',
1120
+ '[class.rxap-loading]': 'loading()',
1121
+ '[class.rxap-loaded]': 'loaded()',
1122
+ '[class.rxap-loading-error]': '!!loadingError()',
1123
+ },
1124
+ // eslint-disable-next-line @angular-eslint/no-outputs-metadata-property
1125
+ outputs: ['ngSubmit'],
1126
+ exportAs: 'rxapForm',
1127
+ standalone: true,
1128
+ }]
1129
+ }], ctorParameters: () => [], propDecorators: { initial: [{ type: i0.Input, args: [{ isSignal: true, alias: "initial", required: false }] }], context: [{ type: i0.Input, args: [{ isSignal: true, alias: "context", required: false }] }], rxapSubmit: [{ type: i0.Output, args: ["rxapSubmit"] }], invalidSubmit: [{ type: i0.Output, args: ["invalidSubmit"] }], submitSuccessful$: [{ type: i0.Output, args: ["submitSuccessful"] }], useFormDefinition: [{ type: i0.Input, args: [{ isSignal: true, alias: "rxapForm", required: false }] }], submitMethod: [{ type: i0.Input, args: [{ isSignal: true, alias: "submitMethod", required: false }] }], loadMethod: [{ type: i0.Input, args: [{ isSignal: true, alias: "loadMethod", required: false }] }], loadFailedMethod: [{ type: i0.Input, args: [{ isSignal: true, alias: "loadFailedMethod", required: false }] }], loadSuccessfulMethod: [{ type: i0.Input, args: [{ isSignal: true, alias: "loadSuccessfulMethod", required: false }] }], submitFailedMethod: [{ type: i0.Input, args: [{ isSignal: true, alias: "submitFailedMethod", required: false }] }], submitSuccessfulMethod: [{ type: i0.Input, args: [{ isSignal: true, alias: "submitSuccessfulMethod", required: false }] }] } });
1130
+
1131
+ class FormLoadedDirective {
1132
+ constructor() {
1133
+ this.formDirective = inject(FormDirective);
1134
+ this.template = inject(TemplateRef);
1135
+ this.viewContainerRef = inject(ViewContainerRef);
1136
+ this.state = toSignal(this.formDirective.loaded$, { initialValue: false });
1137
+ effect(() => {
1138
+ const active = this.state();
1139
+ untracked(() => {
1140
+ this.viewContainerRef.clear();
1141
+ if (active) {
1142
+ this.viewContainerRef.createEmbeddedView(this.template);
1143
+ }
1144
+ });
1145
+ });
1245
1146
  }
1246
- hasErrorAndTouched(error, ...path) {
1247
- return hasErrorAndTouched(this, error, ...path);
1147
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormLoadedDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
1148
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: FormLoadedDirective, isStandalone: true, selector: "[rxapFormLoaded]", ngImport: i0 }); }
1149
+ }
1150
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormLoadedDirective, decorators: [{
1151
+ type: Directive,
1152
+ args: [{
1153
+ selector: '[rxapFormLoaded]',
1154
+ standalone: true,
1155
+ }]
1156
+ }], ctorParameters: () => [] });
1157
+
1158
+ class FormLoadingErrorDirective {
1159
+ constructor() {
1160
+ this.formDirective = inject(FormDirective);
1161
+ this.template = inject(TemplateRef);
1162
+ this.viewContainerRef = inject(ViewContainerRef);
1163
+ this.error = toSignal(this.formDirective.loadingError$, { initialValue: null });
1164
+ effect(() => {
1165
+ const error = this.error();
1166
+ untracked(() => {
1167
+ this.viewContainerRef.clear();
1168
+ if (error !== null) {
1169
+ this.viewContainerRef.createEmbeddedView(this.template, { $implicit: error });
1170
+ }
1171
+ });
1172
+ });
1248
1173
  }
1249
- hasErrorAndDirty(error, ...path) {
1250
- return hasErrorAndDirty(this, error, ...path);
1174
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormLoadingErrorDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
1175
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: FormLoadingErrorDirective, isStandalone: true, selector: "[rxapFormLoadingError]", ngImport: i0 }); }
1176
+ }
1177
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormLoadingErrorDirective, decorators: [{
1178
+ type: Directive,
1179
+ args: [{
1180
+ selector: '[rxapFormLoadingError]',
1181
+ standalone: true,
1182
+ }]
1183
+ }], ctorParameters: () => [] });
1184
+
1185
+ class FormLoadingDirective {
1186
+ constructor() {
1187
+ this.formDirective = inject(FormDirective);
1188
+ this.template = inject(TemplateRef);
1189
+ this.viewContainerRef = inject(ViewContainerRef);
1190
+ this.state = toSignal(this.formDirective.loading$, { initialValue: false });
1191
+ effect(() => {
1192
+ const active = this.state();
1193
+ untracked(() => {
1194
+ this.viewContainerRef.clear();
1195
+ if (active) {
1196
+ this.viewContainerRef.createEmbeddedView(this.template);
1197
+ }
1198
+ });
1199
+ });
1251
1200
  }
1252
- setEnable(enable = true, opts) {
1253
- enableControl(this, enable, opts);
1201
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormLoadingDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
1202
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: FormLoadingDirective, isStandalone: true, selector: "[rxapFormLoading]", ngImport: i0 }); }
1203
+ }
1204
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormLoadingDirective, decorators: [{
1205
+ type: Directive,
1206
+ args: [{
1207
+ selector: '[rxapFormLoading]',
1208
+ standalone: true,
1209
+ }]
1210
+ }], ctorParameters: () => [] });
1211
+
1212
+ class FormResetDirective extends ConfirmClick {
1213
+ constructor() {
1214
+ super(...arguments);
1215
+ this.formDirective = inject(FormDirective);
1216
+ this.type = input('button', ...(ngDevMode ? [{ debugName: "type" }] : /* istanbul ignore next */ []));
1254
1217
  }
1255
- setDisable(disable = true, opts) {
1256
- disableControl(this, disable, opts);
1218
+ execute() {
1219
+ this.formDirective.reset();
1257
1220
  }
1221
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormResetDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
1222
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.9", type: FormResetDirective, isStandalone: true, selector: "[rxapFormReset]", inputs: { type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "type": "type()" } }, usesInheritance: true, ngImport: i0 }); }
1258
1223
  }
1224
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormResetDirective, decorators: [{
1225
+ type: Directive,
1226
+ args: [{
1227
+ selector: '[rxapFormReset]',
1228
+ host: {
1229
+ '[type]': 'type()',
1230
+ },
1231
+ standalone: true,
1232
+ }]
1233
+ }], propDecorators: { type: [{ type: i0.Input, args: [{ isSignal: true, alias: "type", required: false }] }] } });
1259
1234
 
1260
- class RxapFormControl extends UntypedFormControl {
1261
- /**
1262
- * @internal
1263
- */
1264
- get rxapFormDefinition() {
1265
- return this.parent.rxapFormDefinition;
1235
+ class FormSubmitFailedDirective {
1236
+ constructor() {
1237
+ this.formDirective = inject(FormDirective);
1238
+ this.template = inject(TemplateRef);
1239
+ this.viewContainerRef = inject(ViewContainerRef);
1240
+ this.error = toSignal(this.formDirective.submitError$, { initialValue: null });
1241
+ effect(() => {
1242
+ const error = this.error();
1243
+ untracked(() => {
1244
+ this.viewContainerRef.clear();
1245
+ if (error !== null) {
1246
+ this.viewContainerRef.createEmbeddedView(this.template, { $implicit: error });
1247
+ }
1248
+ });
1249
+ });
1266
1250
  }
1267
- get initialState() {
1268
- return this._initialState;
1251
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormSubmitFailedDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
1252
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: FormSubmitFailedDirective, isStandalone: true, selector: "[rxapFormSubmitFailed]", ngImport: i0 }); }
1253
+ }
1254
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormSubmitFailedDirective, decorators: [{
1255
+ type: Directive,
1256
+ args: [{
1257
+ selector: '[rxapFormSubmitFailed]',
1258
+ standalone: true,
1259
+ }]
1260
+ }], ctorParameters: () => [] });
1261
+
1262
+ class FormSubmitInvalidDirective {
1263
+ constructor() {
1264
+ this.formDirective = inject(FormDirective);
1265
+ this.template = inject(TemplateRef);
1266
+ this.viewContainerRef = inject(ViewContainerRef);
1267
+ outputToObservable(this.formDirective.invalidSubmit).pipe(takeUntilDestroyed()).subscribe(result => {
1268
+ this.viewContainerRef.clear();
1269
+ this.viewContainerRef.createEmbeddedView(this.template, { $implicit: result });
1270
+ });
1269
1271
  }
1270
- get readonly() {
1271
- return this.parent?.readonly ?? this._readonly;
1272
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormSubmitInvalidDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
1273
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: FormSubmitInvalidDirective, isStandalone: true, selector: "[rxapFormSubmitInvalid]", ngImport: i0 }); }
1274
+ }
1275
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormSubmitInvalidDirective, decorators: [{
1276
+ type: Directive,
1277
+ args: [{
1278
+ selector: '[rxapFormSubmitInvalid]',
1279
+ standalone: true,
1280
+ }]
1281
+ }], ctorParameters: () => [] });
1282
+
1283
+ class FormSubmitSuccessfulDirective {
1284
+ constructor() {
1285
+ this.formDirective = inject(FormDirective);
1286
+ this.template = inject(TemplateRef);
1287
+ this.viewContainerRef = inject(ViewContainerRef);
1288
+ outputToObservable(this.formDirective.submitSuccessful$).pipe(takeUntilDestroyed()).subscribe(result => {
1289
+ this.viewContainerRef.clear();
1290
+ this.viewContainerRef.createEmbeddedView(this.template, { $implicit: result });
1291
+ });
1272
1292
  }
1273
- set readonly(value) {
1274
- this._readonly = value;
1275
- this.stateChanges.next();
1293
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormSubmitSuccessfulDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
1294
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: FormSubmitSuccessfulDirective, isStandalone: true, selector: "[rxapFormSubmitSuccessful]", ngImport: i0 }); }
1295
+ }
1296
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormSubmitSuccessfulDirective, decorators: [{
1297
+ type: Directive,
1298
+ args: [{
1299
+ selector: '[rxapFormSubmitSuccessful]',
1300
+ standalone: true,
1301
+ }]
1302
+ }], ctorParameters: () => [] });
1303
+
1304
+ class FormSubmitDirective extends ConfirmClick {
1305
+ constructor() {
1306
+ super(...arguments);
1307
+ this.formDirective = inject(FormDirective);
1308
+ this.router = inject(Router, { optional: true }) ?? null;
1309
+ this.type = input('button', ...(ngDevMode ? [{ debugName: "type" }] : /* istanbul ignore next */ []));
1310
+ this.resetAfterSubmit = input(false, { ...(ngDevMode ? { debugName: "resetAfterSubmit" } : /* istanbul ignore next */ {}), transform: coerceBoolean });
1311
+ this.navigateAfterSubmit = input(...(ngDevMode ? [undefined, { debugName: "navigateAfterSubmit" }] : /* istanbul ignore next */ []));
1312
+ this.afterSubmit = output();
1313
+ this.disableWhileSubmitting = input(true, ...(ngDevMode ? [{ debugName: "disableWhileSubmitting" }] : /* istanbul ignore next */ []));
1314
+ this.submitting = toSignal(this.formDirective.submitting$, { initialValue: false });
1315
+ this.disabled = computed(() => this.disableWhileSubmitting() && this.submitting(), ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
1276
1316
  }
1277
- get controlPath() {
1278
- const parent = this.parent;
1279
- if (parent) {
1280
- if (parent.controlPath) {
1281
- if (parent === this.root) {
1282
- return this.controlId;
1283
- }
1284
- else {
1285
- return [parent.controlPath, this.controlId].join('.');
1317
+ execute() {
1318
+ this.formDirective.form.markAllAsDirty();
1319
+ this.formDirective.form.markAllAsTouched();
1320
+ this.subscription = outputToObservable(this.formDirective.rxapSubmit).pipe(take(1), tap(value => {
1321
+ const clonedValue = clone(value);
1322
+ this.afterSubmit.emit(clonedValue);
1323
+ if (this.resetAfterSubmit()) {
1324
+ this.formDirective.reset();
1325
+ }
1326
+ const navigateAfterSubmit = this.navigateAfterSubmit();
1327
+ if (Array.isArray(navigateAfterSubmit)) {
1328
+ if (!this.router) {
1329
+ throw new Error('Could not resolve the router!');
1286
1330
  }
1331
+ return this.router.navigate(navigateAfterSubmit);
1287
1332
  }
1288
- }
1289
- return this.controlId;
1290
- }
1291
- get fullControlPath() {
1292
- const parent = this.parent;
1293
- if (parent) {
1294
- if (parent.fullControlPath) {
1295
- return [parent.fullControlPath, this.controlId].join('.');
1296
- }
1297
- }
1298
- return this.controlId;
1299
- }
1300
- constructor(formState, options) {
1301
- super(formState, options);
1302
- this._readonly = false;
1303
- this.touchChanges = new Subject();
1304
- this.dirtyChanges = new Subject();
1305
- this.touch$ = this.touchChanges
1306
- .asObservable()
1307
- .pipe(distinctUntilChanged());
1308
- this.dirty$ = this.dirtyChanges
1309
- .asObservable()
1310
- .pipe(distinctUntilChanged());
1311
- this.value$ = controlValueChanges$(this);
1312
- this.disabled$ = controlDisabled$(this);
1313
- this.enabled$ = controlEnabled$(this);
1314
- this.status$ = controlStatusChanges$(this);
1315
- this.errors$ = controlErrorChanges$(this);
1316
- this._onSetValue = [];
1317
- this.stateChanges = new Subject();
1318
- this.readonly$ = controlReadonly$(this);
1319
- this.controlId = options.controlId;
1320
- if (options.disabled) {
1321
- this.disable({ emitEvent: false });
1322
- }
1323
- if (options.readonly) {
1324
- this.readonly = true;
1325
- }
1326
- this._initialState = formState;
1333
+ return Promise.resolve();
1334
+ })).subscribe();
1335
+ this.formDirective.onSubmit(new Event('submit'));
1327
1336
  }
1328
- setValue(valueOrObservable, options) {
1329
- if (isObservable(valueOrObservable)) {
1330
- return valueOrObservable.subscribe((value) => {
1331
- super.setValue(value, options);
1332
- this._onSetValue.forEach((setValueFn) => setValueFn(value, options));
1333
- });
1334
- }
1335
- super.setValue(valueOrObservable, options);
1336
- this._onSetValue.forEach((setValueFn) => setValueFn(valueOrObservable, options));
1337
+ ngOnDestroy() {
1338
+ this.subscription?.unsubscribe();
1337
1339
  }
1338
- patchValue(valueOrObservable, options) {
1339
- if (isObservable(valueOrObservable)) {
1340
- return valueOrObservable.subscribe(value => {
1341
- super.patchValue(value, options);
1342
- if (options?.setInitialValue) {
1343
- this._initialState = value;
1340
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormSubmitDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
1341
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.9", type: FormSubmitDirective, isStandalone: true, selector: "[rxapFormSubmit]", inputs: { type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: false, transformFunction: null }, resetAfterSubmit: { classPropertyName: "resetAfterSubmit", publicName: "resetAfterSubmit", isSignal: true, isRequired: false, transformFunction: null }, navigateAfterSubmit: { classPropertyName: "navigateAfterSubmit", publicName: "navigateAfterSubmit", isSignal: true, isRequired: false, transformFunction: null }, disableWhileSubmitting: { classPropertyName: "disableWhileSubmitting", publicName: "disableWhileSubmitting", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { afterSubmit: "afterSubmit" }, host: { properties: { "disabled": "disabled()", "type": "type()" } }, exportAs: ["rxapFormSubmit"], usesInheritance: true, ngImport: i0 }); }
1342
+ }
1343
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormSubmitDirective, decorators: [{
1344
+ type: Directive,
1345
+ args: [{
1346
+ selector: '[rxapFormSubmit]',
1347
+ host: {
1348
+ '[disabled]': 'disabled()',
1349
+ '[type]': 'type()',
1350
+ },
1351
+ standalone: true,
1352
+ exportAs: 'rxapFormSubmit',
1353
+ }]
1354
+ }], propDecorators: { type: [{ type: i0.Input, args: [{ isSignal: true, alias: "type", required: false }] }], resetAfterSubmit: [{ type: i0.Input, args: [{ isSignal: true, alias: "resetAfterSubmit", required: false }] }], navigateAfterSubmit: [{ type: i0.Input, args: [{ isSignal: true, alias: "navigateAfterSubmit", required: false }] }], afterSubmit: [{ type: i0.Output, args: ["afterSubmit"] }], disableWhileSubmitting: [{ type: i0.Input, args: [{ isSignal: true, alias: "disableWhileSubmitting", required: false }] }] } });
1355
+
1356
+ class FormSubmittingDirective {
1357
+ constructor() {
1358
+ this.formDirective = inject(FormDirective);
1359
+ this.template = inject(TemplateRef);
1360
+ this.viewContainerRef = inject(ViewContainerRef);
1361
+ this.state = toSignal(this.formDirective.submitting$, { initialValue: false });
1362
+ effect(() => {
1363
+ const active = this.state();
1364
+ untracked(() => {
1365
+ this.viewContainerRef.clear();
1366
+ if (active) {
1367
+ this.viewContainerRef.createEmbeddedView(this.template);
1344
1368
  }
1345
1369
  });
1346
- }
1347
- super.patchValue(valueOrObservable, options);
1348
- if (options?.setInitialValue) {
1349
- this._initialState = valueOrObservable;
1350
- }
1351
- }
1352
- disabledWhile(observable, options) {
1353
- return controlDisabledWhile(this, observable, options);
1354
- }
1355
- enabledWhile(observable, options) {
1356
- return controlEnabledWhile(this, observable, options);
1357
- }
1358
- mergeValidators(validators) {
1359
- mergeControlValidators(this, validators);
1360
- }
1361
- mergeAsyncValidators(validators) {
1362
- this.setAsyncValidators([
1363
- // TODO : remove 'as any' if solution for the type overwrite issue is found (above)
1364
- this.asyncValidator,
1365
- ...coerceArray(validators),
1366
- ]);
1367
- this.updateValueAndValidity();
1368
- }
1369
- markAsTouched(opts) {
1370
- super.markAsTouched(opts);
1371
- this.touchChanges.next(true);
1372
- }
1373
- markAsUntouched(opts) {
1374
- super.markAsUntouched(opts);
1375
- this.touchChanges.next(false);
1376
- }
1377
- markAsPristine(opts) {
1378
- super.markAsPristine(opts);
1379
- this.dirtyChanges.next(false);
1380
- }
1381
- markAsDirty(opts) {
1382
- super.markAsDirty(opts);
1383
- this.dirtyChanges.next(true);
1384
- }
1385
- markAllAsDirty() {
1386
- this.markAsDirty({ onlySelf: true });
1370
+ });
1387
1371
  }
1388
- reset(formState, options) {
1389
- const newState = formState ?? this.initialState;
1390
- if (typeof newState === 'function') {
1391
- super.reset(newState(), options);
1372
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormSubmittingDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
1373
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: FormSubmittingDirective, isStandalone: true, selector: "[rxapFormSubmitting]", ngImport: i0 }); }
1374
+ }
1375
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormSubmittingDirective, decorators: [{
1376
+ type: Directive,
1377
+ args: [{
1378
+ selector: '[rxapFormSubmitting]',
1379
+ standalone: true,
1380
+ }]
1381
+ }], ctorParameters: () => [] });
1382
+
1383
+ function ToFormMethod(call) {
1384
+ return { call };
1385
+ }
1386
+ /**
1387
+ * @deprecated use ToFormMethod instead
1388
+ *
1389
+ * @param call the call method implementation
1390
+ */
1391
+ function ToFormSubmitMethod(call) {
1392
+ return ToFormMethod(call);
1393
+ }
1394
+
1395
+ class ParentControlContainerDirective {
1396
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: ParentControlContainerDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
1397
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: ParentControlContainerDirective, isStandalone: true, selector: "[formControlName][parentControlContainer],[formControlGroup][parentControlContainer]", providers: [
1398
+ {
1399
+ provide: ControlContainer,
1400
+ useExisting: ControlContainer,
1401
+ },
1402
+ ], ngImport: i0 }); }
1403
+ }
1404
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: ParentControlContainerDirective, decorators: [{
1405
+ type: Directive,
1406
+ args: [{
1407
+ // eslint-disable-next-line @angular-eslint/directive-selector
1408
+ selector: '[formControlName][parentControlContainer],[formControlGroup][parentControlContainer]',
1409
+ providers: [
1410
+ {
1411
+ provide: ControlContainer,
1412
+ useExisting: ControlContainer,
1413
+ },
1414
+ ],
1415
+ standalone: true,
1416
+ }]
1417
+ }] });
1418
+
1419
+ var MetadataKeys;
1420
+ (function (MetadataKeys) {
1421
+ MetadataKeys["CONTROL_VALIDATORS"] = "rxap/forms/control-validators";
1422
+ MetadataKeys["CONTROL_ASYNC_VALIDATORS"] = "rxap/forms/control-async-validators";
1423
+ MetadataKeys["CONTROL_CHANGES"] = "rxap/forms/control-changes";
1424
+ MetadataKeys["CONTROL_SET_VALUE"] = "rxap/forms/control-set-value";
1425
+ MetadataKeys["FORM_ARRAY_GROUPS"] = "rxap/forms/form-array-groups";
1426
+ MetadataKeys["FORM_ARRAY_CONTROLS"] = "rxap/forms/form-array-controls";
1427
+ MetadataKeys["FORM_GROUPS"] = "rxap/forms/form-groups";
1428
+ MetadataKeys["FORM_CONTROLS"] = "rxap/forms/form-controls";
1429
+ })(MetadataKeys || (MetadataKeys = {}));
1430
+
1431
+ function ControlAsyncValidator(...controlIds) {
1432
+ return function (target, propertyKey) {
1433
+ for (const controlId of controlIds) {
1434
+ setMetadataMapSet(controlId, propertyKey, MetadataKeys.CONTROL_ASYNC_VALIDATORS, target);
1392
1435
  }
1393
- else {
1394
- super.reset(newState, options);
1436
+ };
1437
+ }
1438
+
1439
+ function ControlChange(...controlIds) {
1440
+ return function (target, propertyKey) {
1441
+ for (const controlId of controlIds) {
1442
+ setMetadataMapSet(controlId, propertyKey, MetadataKeys.CONTROL_CHANGES, target);
1395
1443
  }
1396
- }
1397
- setValidators(newValidator, updateValueAndValidity = true) {
1398
- super.setValidators(newValidator);
1399
- if (updateValueAndValidity) {
1400
- super.updateValueAndValidity();
1444
+ };
1445
+ }
1446
+
1447
+ function ControlSetValue(controlId, options = {}) {
1448
+ return function (target, propertyKey) {
1449
+ setMetadataMapSet(controlId, {
1450
+ ...options,
1451
+ propertyKey,
1452
+ }, MetadataKeys.CONTROL_SET_VALUE, target);
1453
+ };
1454
+ }
1455
+
1456
+ function ControlValidator(...controlIds) {
1457
+ return function (target, propertyKey) {
1458
+ for (const controlId of controlIds) {
1459
+ setMetadataMapSet(controlId, propertyKey, MetadataKeys.CONTROL_VALIDATORS, target);
1401
1460
  }
1461
+ };
1462
+ }
1463
+
1464
+ function RxapForm(optionsOrId, className = 'FormDefinition', packageName = '@rxap/forms') {
1465
+ return function (target) {
1466
+ DefinitionMetadata(optionsOrId, className, packageName)(target);
1467
+ };
1468
+ }
1469
+
1470
+ function UseFormArrayGroup(definition, options = {}) {
1471
+ return function (target, propertyKey) {
1472
+ setMetadataMap(propertyKey, {
1473
+ ...options,
1474
+ definition,
1475
+ }, MetadataKeys.FORM_ARRAY_GROUPS, target);
1476
+ };
1477
+ }
1478
+ function UseFormArrayControl(options = {}) {
1479
+ return function (target, propertyKey) {
1480
+ setMetadataMap(propertyKey, options, MetadataKeys.FORM_ARRAY_CONTROLS, target);
1481
+ };
1482
+ }
1483
+
1484
+ function UseFormControl(options = {}) {
1485
+ return function (target, propertyKey) {
1486
+ setMetadataMap(propertyKey, options, MetadataKeys.FORM_CONTROLS, target);
1487
+ };
1488
+ }
1489
+
1490
+ function UseFormGroup(definition, options = {}) {
1491
+ return function (target, propertyKey) {
1492
+ setMetadataMap(propertyKey, {
1493
+ ...options,
1494
+ definition,
1495
+ }, MetadataKeys.FORM_GROUPS, target);
1496
+ };
1497
+ }
1498
+
1499
+ function getControlValue(control) {
1500
+ if (control.getRawValue) {
1501
+ return control.getRawValue();
1402
1502
  }
1403
- setAsyncValidators(newValidator, updateValueAndValidity = true) {
1404
- super.setAsyncValidators(newValidator);
1405
- if (updateValueAndValidity) {
1406
- super.updateValueAndValidity();
1407
- }
1503
+ return control.value;
1504
+ }
1505
+ function controlValueChanges$(control) {
1506
+ return merge(defer(() => of(getControlValue(control))), control.valueChanges.pipe(map(() => getControlValue(control))));
1507
+ }
1508
+ function controlDisabled$(control) {
1509
+ return merge(defer(() => of(control.disabled)), merge(control.statusChanges, control.stateChanges?.asObservable() ?? EMPTY).pipe(map(() => control.disabled), distinctUntilChanged()));
1510
+ }
1511
+ function controlEnabled$(control) {
1512
+ return merge(defer(() => of(control.enabled)), merge(control.statusChanges, control.stateChanges?.asObservable() ?? EMPTY).pipe(map(() => control.enabled), distinctUntilChanged()));
1513
+ }
1514
+ function controlReadonly$(control) {
1515
+ return merge(defer(() => of(control.readonly ?? false)), merge(control.statusChanges, control.stateChanges?.asObservable() ?? EMPTY).pipe(map(() => control.readonly ?? false), distinctUntilChanged()));
1516
+ }
1517
+ function controlStatusChanges$(control) {
1518
+ return merge(defer(() => of(control.status)), control.statusChanges.pipe(map(() => control.status), distinctUntilChanged()));
1519
+ }
1520
+ function controlErrorChanges$(control) {
1521
+ return merge(defer(() => of(control.errors)), control.valueChanges.pipe(map(() => control.errors)), control.statusChanges.pipe(map(() => control.errors))).pipe(distinctUntilChanged((a, b) => equals(a, b)));
1522
+ }
1523
+ function enableControl(control, enabled, opts) {
1524
+ if (enabled) {
1525
+ control.enable(opts);
1408
1526
  }
1409
- validateOn(observableValidation) {
1410
- return validateControlOn(this, observableValidation);
1527
+ else {
1528
+ control.disable(opts);
1411
1529
  }
1412
- getError(errorCode) {
1413
- return super.getError(errorCode);
1530
+ }
1531
+ function disableControl(control, disabled, opts) {
1532
+ enableControl(control, !disabled, opts);
1533
+ }
1534
+ function controlDisabledWhile(control, observable, opts) {
1535
+ return observable.subscribe(isDisabled => disableControl(control, isDisabled, opts));
1536
+ }
1537
+ function controlEnabledWhile(control, observable, opts) {
1538
+ return observable.subscribe(isEnabled => enableControl(control, isEnabled, opts));
1539
+ }
1540
+ function mergeControlValidators(control, validators) {
1541
+ control.setValidators([...coerceArray(control.validator), ...coerceArray(validators)]);
1542
+ control.updateValueAndValidity();
1543
+ }
1544
+ function validateControlOn(control, validation) {
1545
+ return validation.subscribe(maybeError => {
1546
+ control.setErrors(maybeError);
1547
+ });
1548
+ }
1549
+ function hasErrorAndTouched(control, error, path) {
1550
+ const hasError = control.hasError(error, !path || path.length === 0 ? undefined : path);
1551
+ return hasError && control.touched;
1552
+ }
1553
+ function hasErrorAndDirty(control, error, path) {
1554
+ const hasError = control.hasError(error, !path || path.length === 0 ? undefined : path);
1555
+ return hasError && control.dirty;
1556
+ }
1557
+ function markAllDirty(control) {
1558
+ control.markAsDirty({ onlySelf: true });
1559
+ control._forEachChild((_control) => _control.markAllAsDirty());
1560
+ }
1561
+ function markAllPristine(control) {
1562
+ control.markAsPristine({ onlySelf: true });
1563
+ control._forEachChild((_control) => _control.markAllAsPristine());
1564
+ }
1565
+ function markAllUntouched(control) {
1566
+ control.markAsUntouched({ onlySelf: true });
1567
+ control._forEachChild((_control) => _control.markAllAsUntouched());
1568
+ }
1569
+ function selectControlValue$(control, mapFn) {
1570
+ return control.value$.pipe(map(mapFn), distinctUntilChanged());
1571
+ }
1572
+
1573
+ class ControlValueAccessor {
1574
+ constructor() {
1575
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
1576
+ this.onChange = (value) => {
1577
+ };
1578
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
1579
+ this.onTouched = () => {
1580
+ };
1581
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
1582
+ this.setDisabledState = (isDisabled) => {
1583
+ };
1414
1584
  }
1415
- hasError(errorCode) {
1416
- return super.hasError(errorCode);
1585
+ registerOnChange(fn) {
1586
+ this.onChange = fn;
1417
1587
  }
1418
- setErrors(errors, opts = {}) {
1419
- return super.setErrors(errors, opts);
1588
+ registerOnTouched(fn) {
1589
+ this.onTouched = fn;
1420
1590
  }
1421
- setError(key, value, opts = {}) {
1422
- super.setErrors({ [key]: value }, opts);
1591
+ }
1592
+
1593
+ class RxapFormArray extends UntypedFormArray {
1594
+ get readonly() {
1595
+ return this.parent?.readonly ?? this._readonly;
1423
1596
  }
1424
- hasErrorAndTouched(error) {
1425
- return hasErrorAndTouched(this, error);
1597
+ set readonly(value) {
1598
+ this._readonly = value;
1599
+ this.controls.forEach(control => control.stateChanges?.next());
1426
1600
  }
1427
- hasErrorAndDirty(error) {
1428
- return hasErrorAndDirty(this, error);
1601
+ /**
1602
+ * @internal
1603
+ */
1604
+ get rxapFormDefinition() {
1605
+ return this.parent.rxapFormDefinition;
1429
1606
  }
1430
- setEnable(enable = true, opts) {
1431
- enableControl(this, enable, opts);
1607
+ get controlPath() {
1608
+ const parent = this.parent;
1609
+ if (parent) {
1610
+ if (parent.controlPath) {
1611
+ if (parent === this.root) {
1612
+ return this.controlId;
1613
+ }
1614
+ else {
1615
+ return [parent.controlPath, this.controlId].join('.');
1616
+ }
1617
+ }
1618
+ }
1619
+ return this.controlId;
1432
1620
  }
1433
- setDisable(disable = true, opts) {
1434
- disableControl(this, disable, opts);
1621
+ get fullControlPath() {
1622
+ const parent = this.parent;
1623
+ if (parent) {
1624
+ if (parent.fullControlPath) {
1625
+ return [parent.fullControlPath, this.controlId].join('.');
1626
+ }
1627
+ }
1628
+ return this.controlId;
1435
1629
  }
1436
- registerOnSetValue(setValueFn) {
1437
- this._onSetValue.push(setValueFn);
1630
+ constructor(controls, options) {
1631
+ super(controls, options);
1632
+ this.controls = controls;
1633
+ this._readonly = false;
1634
+ this.value$ = controlValueChanges$(this);
1635
+ this.disabled$ = controlDisabled$(this);
1636
+ this.enabled$ = controlEnabled$(this);
1637
+ this.status$ = controlStatusChanges$(this);
1638
+ this.errors$ = controlErrorChanges$(this);
1639
+ this.touchChanges = new Subject();
1640
+ this.touch$ = this.touchChanges
1641
+ .asObservable()
1642
+ .pipe(distinctUntilChanged());
1643
+ this.dirtyChanges = new Subject();
1644
+ this.dirty$ = this.dirtyChanges
1645
+ .asObservable()
1646
+ .pipe(distinctUntilChanged());
1647
+ this.controlId = options.controlId;
1648
+ this._builder = options.builder;
1649
+ this._controlInsertedFn = options.controlInsertedFn;
1650
+ this._controlRemovedFn = options.controlRemovedFn;
1438
1651
  }
1439
- }
1440
-
1441
- /* eslint-disable @typescript-eslint/ban-types */
1442
- class FormArrayControlManager {
1443
- constructor(form, controlId) {
1444
- this.form = form;
1445
- this.controlId = controlId;
1652
+ select(mapFn) {
1653
+ return this.value$.pipe(map(mapFn), distinctUntilChanged());
1446
1654
  }
1447
- inserted(index, controlOrDefinition) {
1448
- const controlContainer = this.form[this.controlId];
1449
- if (Array.isArray(controlContainer)) {
1450
- controlContainer.splice(index, 0, controlOrDefinition);
1451
- }
1452
- else {
1453
- throw new Error('Could not register inserted control or definition. The control id does not points to an array of control or definition instance!');
1454
- }
1655
+ at(index) {
1656
+ return super.at(index);
1455
1657
  }
1456
- removed(index) {
1457
- const controlContainer = this.form[this.controlId];
1458
- if (Array.isArray(controlContainer)) {
1459
- controlContainer.splice(index, 1);
1460
- }
1461
- else {
1462
- throw new Error('Could not register inserted control or definition. The control id does not points to an array of control or definition instance!');
1463
- }
1658
+ getRawValue() {
1659
+ return super.getRawValue();
1464
1660
  }
1465
- }
1466
- class RxapFormBuilder {
1467
- constructor(definition, injector = Injector.NULL, providers = []) {
1468
- this.definition = definition;
1469
- this.injector = injector;
1470
- this.formArrayGroups = this.extractArrayGroups();
1471
- this.formArrayControls = this.extractArrayControls();
1472
- this.formControls = this.extractControls();
1473
- this.formGroups = this.extractGroups();
1474
- this.validators = this.extractValidators();
1475
- this.asyncValidators = this.extractAsyncValidators();
1476
- this.controlChanges = this.extractControlChanges();
1477
- this.controlSetValue = this.extractControlSetValue();
1478
- const formOptions = (this.formOptions = this.extractFormOptions());
1479
- // merge the providers from the from options with the providers from the
1480
- // constructor. If the provider is defined in the form options and constructor
1481
- // then the provider from the constructor will be used.
1482
- this.providers = [...providers, ...(formOptions.providers ?? [])].filter((provider, index, self) => provider['provide'] &&
1483
- self.findIndex((selfProvider) => selfProvider.provide &&
1484
- selfProvider.provide === provider.provide) === index);
1661
+ insert(index, control) {
1662
+ if (isDevMode()) {
1663
+ console.warn('It is not recommend to use the FormArray.insert method');
1664
+ }
1665
+ return super.insert(index, control);
1485
1666
  }
1486
- build(state = {}, options = {}) {
1487
- const injector = Injector.create({
1488
- name: `rxap/form-builder/${this.formOptions.id}`,
1489
- parent: this.injector,
1490
- providers: this.providers,
1667
+ /**
1668
+ * inserts a new control at the specified index. If the index is undefined
1669
+ * the new control will be added to the end.
1670
+ *
1671
+ * @param index (optional) the index where the control should be created
1672
+ * @param state (optional) the initial state of the new control
1673
+ * @param options (optional) ControlEventOptions
1674
+ */
1675
+ insertAt(index, state, options) {
1676
+ const insertIndex = index ?? this.controls.length;
1677
+ const length = this.controls.length;
1678
+ const controlOrDefinition = this._builder(state, {
1679
+ controlId: insertIndex.toFixed(0),
1491
1680
  });
1492
- let form;
1493
- // don't use the notFoundValue feature of the injector.
1494
- // if used for each call of the get method an "empty" or "fallback"
1495
- // instance is created
1496
- try {
1497
- form = injector.get(this.definition);
1681
+ this._controlInsertedFn(insertIndex, controlOrDefinition);
1682
+ if (insertIndex < this.controls.length) {
1683
+ // update the control ids for all controls, that are moved.
1684
+ for (let i = insertIndex; i < this.controls.length; i++) {
1685
+ Reflect.set(this.controls[i], 'controlId', (i + 1).toFixed(0));
1686
+ }
1498
1687
  }
1499
- catch (e) {
1500
- const message = typeof e?.message === 'string' ? e.message : '';
1501
- // Angular 21 throws a RuntimeError NG0201 ("No provider found for `X`.")
1502
- // instead of the old NullInjectorError ("No provider for X"). Detect both.
1503
- const isNoProvider = e?.name === 'NullInjectorError' ||
1504
- message.includes('NG0201') ||
1505
- message.includes('No provider');
1506
- if (isNoProvider && message.includes(this.definition.name)) {
1507
- if (isDevMode()) {
1508
- console.warn(`Could not inject the definition instance. Fallback and call the constructor of the definition class: ${message}`);
1509
- }
1510
- form = new this.definition();
1688
+ if (length === this.controls.length) {
1689
+ // the _controlInsertedFn has not yet added the new control to the form array
1690
+ // call the super insert after the update, bc the insert method will
1691
+ // trigger a change detection
1692
+ if (controlOrDefinition instanceof AbstractControl) {
1693
+ super.insert(insertIndex, controlOrDefinition, options);
1511
1694
  }
1512
1695
  else {
1513
- throw new Error(`Could not inject the definition instance: ${message}`);
1696
+ super.insert(insertIndex, controlOrDefinition.rxapFormGroup, options);
1514
1697
  }
1515
1698
  }
1516
- const controls = {};
1517
- this.buildControls(state, form, controls);
1518
- this.buildGroups(state, form, controls);
1519
- this.buildArrayGroups(state, form, controls);
1520
- this.buildArrayControls(state, form, controls);
1521
- const formOptions = {
1522
- ...this.formOptions,
1523
- controlId: options.controlId ?? (options.id ? options.id : this.formOptions.id),
1524
- ...options,
1525
- };
1526
- form.rxapFormGroup = new RxapFormGroup(controls, formOptions);
1527
- Reflect.set(form.rxapFormGroup, '_rxapFormDefinition', form);
1528
- form.rxapMetadata = this.formOptions;
1529
- if (HasRxapOnInitMethod(form)) {
1530
- form.rxapOnInit();
1531
- }
1532
- for (const control of Object.values(form.rxapFormGroup.controls)) {
1533
- if (control.controlId) {
1534
- const controlSetValueOnInit = Array.from(this.controlSetValue.get(control.controlId) ?? []).filter((controlSetValueOptions) => controlSetValueOptions.initial);
1535
- for (const onSetValue of this.coerceToFnArray(form, controlSetValueOnInit)) {
1536
- onSetValue(control.value, { initial: true });
1537
- }
1699
+ else {
1700
+ if (controlOrDefinition instanceof AbstractControl) {
1701
+ controlOrDefinition.setParent(this);
1702
+ controlOrDefinition['_registerOnCollectionChange']?.(this['_onCollectionChange']);
1703
+ }
1704
+ else {
1705
+ controlOrDefinition.rxapFormGroup.setParent(this);
1706
+ controlOrDefinition.rxapFormGroup['_registerOnCollectionChange']?.(this['_onCollectionChange']);
1538
1707
  }
1708
+ this.updateValueAndValidity({ emitEvent: options?.emitEvent });
1539
1709
  }
1540
- return form;
1541
1710
  }
1542
- buildArrayControls(builderFormState, form, controls) {
1543
- for (const [controlId, options] of this.formArrayControls.entries()) {
1544
- const formState = this.coerceToArrayFormState(controlId, [], builderFormState, options.state);
1545
- assertIsArray(formState);
1546
- const formControls = formState.map((fs, index) => new RxapFormControl(fs, { controlId: index.toFixed(0) }));
1547
- const manager = new FormArrayControlManager(form, controlId);
1548
- const formArray = (formControls.rxapFormArray =
1549
- controls[controlId] =
1550
- new RxapFormArray(
1551
- // TODO : add the formControlOptions property. To definition the form control options
1552
- formControls, {
1553
- ...options,
1554
- controlId,
1555
- validators: [],
1556
- asyncValidators: [],
1557
- controlInsertedFn: manager.inserted.bind(manager),
1558
- controlRemovedFn: manager.removed.bind(manager),
1559
- builder: (state, controlOptions) => new RxapFormControl(state, controlOptions),
1560
- }));
1561
- // TODO : add support for injectable validators
1562
- formArray.setValidators(this.coerceToValidatorArray(form, options.validators, this.validators.get(controlId)), false);
1563
- formArray.setAsyncValidators(this.coerceToValidatorArray(form, options.asyncValidators, this.asyncValidators.get(controlId)), false);
1564
- Reflect.set(form, controlId, formControls);
1565
- }
1711
+ disabledWhile(observable, options) {
1712
+ return controlDisabledWhile(this, observable, options);
1566
1713
  }
1567
- buildArrayGroups(builderFormState, form, controls) {
1568
- for (const [controlId, options] of this.formArrayGroups.entries()) {
1569
- const formState = this.coerceToArrayFormState(controlId, [], builderFormState, options.state);
1570
- assertIsArray(formState);
1571
- const formGroupBuilder = new RxapFormBuilder(options.definition, this.injector, this.providers);
1572
- // TODO : add the formGroupOptions property. To definition of the form group options
1573
- const formGroupDefinitions = formState.map((fs, index) => formGroupBuilder.build(fs, { id: index.toFixed(0) }));
1574
- const manager = new FormArrayControlManager(form, controlId);
1575
- const formArray = (formGroupDefinitions.rxapFormArray =
1576
- controls[controlId] =
1577
- new RxapFormArray(formGroupDefinitions.map((fgd) => fgd.rxapFormGroup), {
1578
- ...options,
1579
- builder: formGroupBuilder.build.bind(formGroupBuilder),
1580
- controlId,
1581
- validators: [],
1582
- asyncValidators: [],
1583
- controlInsertedFn: manager.inserted.bind(manager),
1584
- controlRemovedFn: manager.removed.bind(manager),
1585
- }));
1586
- // TODO : add support for injectable validators
1587
- formArray.setValidators(this.coerceToValidatorArray(form, options.validators, this.validators.get(controlId)), false);
1588
- formArray.setAsyncValidators(this.coerceToValidatorArray(form, options.asyncValidators, this.asyncValidators.get(controlId)), false);
1589
- Reflect.set(form, controlId, formGroupDefinitions);
1590
- }
1714
+ enabledWhile(observable, options) {
1715
+ return controlEnabledWhile(this, observable, options);
1591
1716
  }
1592
- buildGroups(builderFormState, form, controls) {
1593
- for (const [controlId, options] of this.formGroups.entries()) {
1594
- const formState = this.coerceToGroupFormState(controlId, {}, builderFormState, options.state);
1595
- assertIsObject(formState);
1596
- const formGroupDefinition = new RxapFormBuilder(options.definition, this.injector, this.providers).build(formState, {
1597
- ...options,
1598
- validators: [],
1599
- asyncValidators: [],
1717
+ mergeValidators(validators) {
1718
+ mergeControlValidators(this, validators);
1719
+ }
1720
+ mergeAsyncValidators(validators) {
1721
+ this.setAsyncValidators([
1722
+ ...coerceArray(this.asyncValidator),
1723
+ ...coerceArray(validators),
1724
+ ]);
1725
+ this.updateValueAndValidity();
1726
+ }
1727
+ markAllAsDirty() {
1728
+ markAllDirty(this);
1729
+ }
1730
+ markAllAsPristine() {
1731
+ markAllPristine(this);
1732
+ }
1733
+ setValue(valueOrObservable, options) {
1734
+ if (isObservable(valueOrObservable)) {
1735
+ return valueOrObservable.subscribe((value) => {
1736
+ super.setValue(value, options);
1600
1737
  });
1601
- controls[controlId] = formGroupDefinition.rxapFormGroup;
1602
- const formGroup = formGroupDefinition.rxapFormGroup;
1603
- // TODO : add support for injectable validators
1604
- formGroup.setValidators(this.coerceToValidatorArray(form, options.validators, this.validators.get(controlId)), false);
1605
- formGroup.setAsyncValidators(this.coerceToValidatorArray(form, options.asyncValidators, this.asyncValidators.get(controlId)), false);
1606
- // set the form group definition instance to the form definition instance
1607
- Reflect.set(form, controlId, formGroupDefinition);
1608
1738
  }
1739
+ super.setValue(valueOrObservable, options);
1609
1740
  }
1610
- buildControls(builderFormState, form, controls) {
1611
- for (const [controlId, options] of this.formControls.entries()) {
1612
- const control = (controls[controlId] = new (options.controlType ??
1613
- RxapFormControl)(this.coerceToControlFormState(controlId, null, builderFormState, options.state), {
1614
- ...options,
1615
- controlId,
1616
- validators: [],
1617
- asyncValidators: [],
1618
- }));
1619
- const injectValidators = [];
1620
- const injectAsyncValidators = [];
1621
- for (const injectValidator of options.injectValidators ?? []) {
1622
- const injectableValidator = this.injector.get(injectValidator);
1623
- if (injectableValidator.validate) {
1624
- injectValidators.push(injectableValidator.validate.bind(injectableValidator));
1625
- }
1626
- if (injectableValidator.asyncValidate) {
1627
- injectAsyncValidators.push(injectableValidator.asyncValidate.bind(injectableValidator));
1628
- }
1629
- }
1630
- control.setValidators(this.coerceToValidatorArray(form, options.validators, this.validators.get(controlId), injectValidators), false);
1631
- control.setAsyncValidators(this.coerceToValidatorArray(form, options.asyncValidators, this.asyncValidators.get(controlId), injectAsyncValidators), false);
1632
- // register all control on change function with the form control
1633
- this.coerceToFnArray(form, this.controlChanges.get(controlId)).forEach((changeFn) => control.registerOnChange(changeFn));
1634
- // register all control on set value function with the form control
1635
- this.coerceToFnArray(form, this.controlSetValue.get(controlId)).forEach((setValueFn) => control.registerOnSetValue(setValueFn));
1636
- if (Array.isArray(options.validators)) {
1637
- if (options.validators.includes(Validators.required) ||
1638
- options.validators.includes(Validators.requiredTrue)) {
1639
- Reflect.set(control, 'hasRequiredValidator', true);
1741
+ markAllAsUntouched() {
1742
+ markAllUntouched(this);
1743
+ }
1744
+ validateOn(observableValidation) {
1745
+ return observableValidation.subscribe((maybeError) => {
1746
+ this.setErrors(maybeError);
1747
+ });
1748
+ }
1749
+ hasErrorAndTouched(errorCode, path) {
1750
+ return hasErrorAndTouched(this, errorCode, path);
1751
+ }
1752
+ _patchValue(value, options) {
1753
+ // Even though the `value` argument type doesn't allow `null` and `undefined` values, the
1754
+ // `patchValue` can be called recursively and inner data structures might have these values, so
1755
+ // we just ignore such cases when a field containing FormArray instance receives `null` or
1756
+ // `undefined` as a value.
1757
+ if (value == null /* both `null` and `undefined` */) {
1758
+ return;
1759
+ }
1760
+ if (options?.strict) {
1761
+ if (this.length > value.length) {
1762
+ for (let index = this.length - 1; index >= value.length; index--) {
1763
+ this.removeAt(index);
1640
1764
  }
1641
1765
  }
1642
- // set the form control instance to the form definition instance
1643
- Reflect.set(form, controlId, control);
1644
1766
  }
1645
- }
1646
- /**
1647
- * Coerce to a function array.
1648
- *
1649
- * @param form the current form definition instance
1650
- * @param methodKeys A set of propertyKeys that points to form
1651
- * definition instance methods
1652
- */
1653
- coerceToFnArray(form, methodKeys) {
1654
- const changes = [];
1655
- if (methodKeys) {
1656
- for (const propertyKeyOrOptions of methodKeys) {
1657
- const propertyKey = typeof propertyKeyOrOptions === 'string'
1658
- ? propertyKeyOrOptions
1659
- : propertyKeyOrOptions.propertyKey;
1660
- assertIsFunction(form[propertyKey]);
1661
- changes.push(form[propertyKey].bind(form));
1767
+ value.forEach((newValue, index) => {
1768
+ if (this.at(index)) {
1769
+ this.at(index)
1770
+ .patchValue(newValue, {
1771
+ ...(options ?? {}),
1772
+ onlySelf: true,
1773
+ });
1662
1774
  }
1663
- }
1664
- return changes;
1775
+ else if (options?.coerce) {
1776
+ this.insertAt(index, value[index]);
1777
+ }
1778
+ });
1779
+ this.updateValueAndValidity(options);
1665
1780
  }
1666
- /**
1667
- * Coerce to a validator function array.
1668
- *
1669
- * @param form the current form definition instance
1670
- * @param optionsValidators The options validator functions
1671
- * @param validatorMethodKeys A set of propertyKeys that points to form
1672
- * definition instance methods
1673
- * @param injectValidators Injected validator functions
1674
- */
1675
- coerceToValidatorArray(form, optionsValidators, validatorMethodKeys, injectValidators) {
1676
- const validators = (optionsValidators ? Array.isArray(optionsValidators) ? optionsValidators : [optionsValidators] : []).slice();
1677
- if (validatorMethodKeys) {
1678
- validatorMethodKeys.forEach((propertyKey) => {
1679
- assertIsFunction(form[propertyKey]);
1680
- validators.push(form[propertyKey].bind(form));
1781
+ patchValue(valueOrObservable, options) {
1782
+ if (isObservable(valueOrObservable)) {
1783
+ return valueOrObservable.subscribe((value) => {
1784
+ this._patchValue(value, options);
1681
1785
  });
1682
1786
  }
1683
- if (injectValidators) {
1684
- validators.push(...injectValidators);
1685
- }
1686
- return validators;
1787
+ this._patchValue(valueOrObservable, options);
1687
1788
  }
1688
- /**
1689
- * Coerce to the form state for the specified controlId. If none form state is
1690
- * found the default form state will be returned.
1691
- *
1692
- * @param controlId A control id
1693
- * @param defaultFormState The default form state
1694
- * @param builderFormState The form state provides as build state parameter
1695
- * @param optionsFormState The form state set by the decorator in the form definition
1696
- */
1697
- coerceToControlFormState(controlId, defaultFormState, builderFormState, optionsFormState) {
1698
- let formState = defaultFormState;
1699
- if (builderFormState && builderFormState[controlId] !== undefined) {
1700
- formState = builderFormState[controlId];
1789
+ hasErrorAndDirty(errorCode, path) {
1790
+ return hasErrorAndDirty(this, errorCode, path);
1791
+ }
1792
+ removeAt(index, opts) {
1793
+ if (isDevMode()) {
1794
+ console.warn('It is not recommend to use the FormArray.removeAt method');
1701
1795
  }
1702
- else if (optionsFormState !== undefined) {
1703
- formState = optionsFormState ?? null;
1796
+ const length = this.controls.length;
1797
+ this._controlRemovedFn(index);
1798
+ if (length === this.controls.length) {
1799
+ super.removeAt(index);
1704
1800
  }
1705
- if (typeof formState === 'function') {
1706
- formState = formState();
1801
+ else {
1802
+ this.updateValueAndValidity({ emitEvent: opts?.emitEvent });
1707
1803
  }
1708
- return formState;
1709
1804
  }
1710
- /**
1711
- * Coerce to the form state for the specified controlId. If none form state is
1712
- * found the default form state will be returned.
1713
- *
1714
- * The difference to the method coerceToControlFormState is that null will be
1715
- * handled as undefined and the defaultFormState is used
1716
- *
1717
- * @param controlId A control id
1718
- * @param defaultFormState The default form state
1719
- * @param builderFormState The form state provides as build state parameter
1720
- * @param optionsFormState The form state set by the decorator in the form definition
1721
- */
1722
- coerceToGroupFormState(controlId, defaultFormState, builderFormState, optionsFormState) {
1723
- let formState = defaultFormState;
1724
- if (builderFormState && builderFormState[controlId]) {
1725
- formState = builderFormState[controlId];
1805
+ setEnable(enable = true, opts) {
1806
+ enableControl(this, enable, opts);
1807
+ }
1808
+ push(control, options) {
1809
+ if (isDevMode()) {
1810
+ console.warn('It is not recommend to use the FormArray.push method');
1726
1811
  }
1727
- else if (optionsFormState) {
1728
- formState = optionsFormState;
1812
+ return super.push(control, options);
1813
+ }
1814
+ setDisable(disable = true, opts) {
1815
+ disableControl(this, disable, opts);
1816
+ }
1817
+ setControl(index, control, options) {
1818
+ if (isDevMode()) {
1819
+ console.warn('It is not recommend to use the FormArray.setControl method');
1729
1820
  }
1730
- if (typeof formState === 'function') {
1731
- formState = formState();
1732
- if (!formState) {
1733
- throw new Error(`The form state function for the form group '${controlId}' returns a empty value (null/undefined)`);
1734
- }
1735
- if (typeof formState !== 'object') {
1736
- throw new Error(`The form state function for the form group '${controlId}' returns a non object like value instead '${typeof formState}'`);
1737
- }
1821
+ return super.setControl(index, control, options);
1822
+ }
1823
+ markAsTouched(opts) {
1824
+ super.markAsTouched(opts);
1825
+ this.touchChanges.next(true);
1826
+ }
1827
+ markAsUntouched(opts) {
1828
+ super.markAsUntouched(opts);
1829
+ this.touchChanges.next(false);
1830
+ }
1831
+ markAsPristine(opts) {
1832
+ super.markAsPristine(opts);
1833
+ this.dirtyChanges.next(false);
1834
+ }
1835
+ markAsDirty(opts) {
1836
+ super.markAsDirty(opts);
1837
+ this.dirtyChanges.next(true);
1838
+ }
1839
+ reset(value, options) {
1840
+ super.reset(value, options);
1841
+ }
1842
+ setValidators(newValidator, updateValueAndValidity = true) {
1843
+ super.setValidators(newValidator);
1844
+ if (updateValueAndValidity) {
1845
+ super.updateValueAndValidity();
1738
1846
  }
1739
- return formState;
1740
1847
  }
1848
+ setAsyncValidators(newValidator, updateValueAndValidity = true) {
1849
+ super.setAsyncValidators(newValidator);
1850
+ if (updateValueAndValidity) {
1851
+ super.updateValueAndValidity();
1852
+ }
1853
+ }
1854
+ hasError(errorCode, path) {
1855
+ return super.hasError(errorCode, path);
1856
+ }
1857
+ setErrors(errors, opts = {}) {
1858
+ return super.setErrors(errors, opts);
1859
+ }
1860
+ getError(errorCode, path) {
1861
+ return super.getError(errorCode, path);
1862
+ }
1863
+ }
1864
+
1865
+ class RxapFormGroup extends UntypedFormGroup {
1741
1866
  /**
1742
- * Coerce to the form state for the specified controlId. If none form state is
1743
- * found the default form state will be returned.
1744
- *
1745
- * The difference to the method coerceToControlFormState is that null will be
1746
- * handled as undefined and the defaultFormState is used
1747
- *
1748
- * @param controlId A control id
1749
- * @param defaultFormState The default form state
1750
- * @param builderFormState The form state provides as build state parameter
1751
- * @param optionsFormState The form state set by the decorator in the form definition
1867
+ * @internal
1752
1868
  */
1753
- coerceToArrayFormState(controlId, defaultFormState, builderFormState, optionsFormState) {
1754
- let formState = defaultFormState;
1755
- if (builderFormState && builderFormState[controlId] && Array.isArray(builderFormState[controlId])) {
1756
- formState = builderFormState[controlId];
1869
+ get rxapFormDefinition() {
1870
+ if (!this.parent) {
1871
+ return this._rxapFormDefinition;
1757
1872
  }
1758
- else if (optionsFormState && Array.isArray(optionsFormState)) {
1759
- formState = optionsFormState;
1873
+ if (this._rxapFormDefinition) {
1874
+ return this._rxapFormDefinition;
1760
1875
  }
1761
- if (typeof formState === 'function') {
1762
- formState = formState();
1763
- if (!formState) {
1764
- throw new Error(`The form state function for the form array '${controlId}' returns a empty value (null/undefined)`);
1876
+ return this.parent.rxapFormDefinition;
1877
+ }
1878
+ get readonly() {
1879
+ return this.parent?.readonly ?? this._readonly;
1880
+ }
1881
+ set readonly(value) {
1882
+ this._readonly = value;
1883
+ Object.values(this.controls ?? {}).forEach(control => control.stateChanges?.next());
1884
+ }
1885
+ get controlPath() {
1886
+ const parent = this.parent;
1887
+ if (parent) {
1888
+ if (parent.controlPath) {
1889
+ if (parent === this.root) {
1890
+ return this.controlId;
1891
+ }
1892
+ else {
1893
+ return [parent.controlPath, this.controlId].join('.');
1894
+ }
1765
1895
  }
1766
- if (!Array.isArray(formState)) {
1767
- throw new Error(`The form state function for the form array '${controlId}' returns a non array like value instead '${typeof formState}'`);
1896
+ }
1897
+ return '';
1898
+ }
1899
+ get fullControlPath() {
1900
+ const parent = this.parent;
1901
+ if (parent) {
1902
+ if (parent.fullControlPath) {
1903
+ return [parent.fullControlPath, this.controlId].join('.');
1768
1904
  }
1769
1905
  }
1770
- return formState;
1906
+ return this.controlId;
1907
+ }
1908
+ constructor(controls, options) {
1909
+ super(controls, options);
1910
+ this.controls = controls;
1911
+ this._readonly = false;
1912
+ this.touchChanges = new Subject();
1913
+ this.dirtyChanges = new Subject();
1914
+ this.touch$ = this.touchChanges.asObservable().pipe(distinctUntilChanged());
1915
+ this.dirty$ = this.dirtyChanges.asObservable().pipe(distinctUntilChanged());
1916
+ this.value$ = controlValueChanges$(this);
1917
+ this.disabled$ = controlDisabled$(this);
1918
+ this.enabled$ = controlEnabled$(this);
1919
+ this.status$ = controlStatusChanges$(this);
1920
+ this.errors$ = controlErrorChanges$(this);
1921
+ this.controlId = options.controlId;
1771
1922
  }
1772
- extractControlChanges() {
1773
- return (getMetadata(MetadataKeys.CONTROL_CHANGES, this.definition.prototype) ??
1774
- new Map());
1923
+ select(mapFn) {
1924
+ return selectControlValue$(this, mapFn);
1775
1925
  }
1776
- extractControlSetValue() {
1777
- return (getMetadata(MetadataKeys.CONTROL_SET_VALUE, this.definition.prototype) ??
1778
- new Map());
1926
+ getRawValue() {
1927
+ return super.getRawValue();
1779
1928
  }
1780
- extractValidators() {
1781
- return (getMetadata(MetadataKeys.CONTROL_VALIDATORS, this.definition.prototype) ??
1782
- new Map());
1929
+ get(path) {
1930
+ return super.get(path);
1783
1931
  }
1784
- extractAsyncValidators() {
1785
- return (getMetadata(MetadataKeys.CONTROL_ASYNC_VALIDATORS, this.definition.prototype) ?? new Map());
1932
+ getControl(...names) {
1933
+ return this.get(names.join('.'));
1786
1934
  }
1787
- extractArrayGroups() {
1788
- return (getMetadata(MetadataKeys.FORM_ARRAY_GROUPS, this.definition.prototype) ??
1789
- new Map());
1935
+ addControl(name, control) {
1936
+ super.addControl(name, control);
1790
1937
  }
1791
- extractArrayControls() {
1792
- return (getMetadata(MetadataKeys.FORM_ARRAY_CONTROLS, this.definition.prototype) ?? new Map());
1938
+ removeControl(name) {
1939
+ super.removeControl(name);
1793
1940
  }
1794
- extractGroups() {
1795
- return (getMetadata(MetadataKeys.FORM_GROUPS, this.definition.prototype) ??
1796
- new Map());
1941
+ contains(controlName) {
1942
+ return super.contains(controlName);
1797
1943
  }
1798
- extractControls() {
1799
- return (getMetadata(MetadataKeys.FORM_CONTROLS, this.definition.prototype) ??
1800
- new Map());
1944
+ setControl(name, control) {
1945
+ super.setControl(name, control);
1801
1946
  }
1802
- extractFormOptions() {
1803
- const options = GetDefinitionMetadata(this.definition);
1804
- if (!options || !options['id']) {
1805
- throw new Error('Ensure that the @UseForm decorator is used.');
1947
+ setValue(valueOrObservable, options) {
1948
+ if (isObservable(valueOrObservable)) {
1949
+ return valueOrObservable.subscribe((value) =>
1950
+ // TODO : refactor RxapFormGroup to typed FormGroup
1951
+ super.setValue(value, options));
1806
1952
  }
1807
- if (!options['providers']) {
1808
- options['providers'] = [];
1953
+ super.setValue(valueOrObservable, options);
1954
+ }
1955
+ _patchValue(value, options) {
1956
+ // Even though the `value` argument type doesn't allow `null` and `undefined` values, the
1957
+ // `patchValue` can be called recursively and inner data structures might have these values, so
1958
+ // we just ignore such cases when a field containing FormGroup instance receives `null` or
1959
+ // `undefined` as a value.
1960
+ if (value == null /* both `null` and `undefined` */) {
1961
+ return;
1809
1962
  }
1810
- return options;
1963
+ Object.keys(value).forEach(name => {
1964
+ // TODO : resolve type issue
1965
+ const controls = this.controls;
1966
+ if (controls[name]) {
1967
+ controls[name].patchValue(value[name], {
1968
+ ...(options ?? {}),
1969
+ onlySelf: true,
1970
+ });
1971
+ }
1972
+ });
1973
+ this.updateValueAndValidity(options);
1811
1974
  }
1812
- }
1813
-
1814
- class FormDirective extends FormGroupDirective {
1815
- get submitting() {
1816
- return this.submitting$.value;
1975
+ patchValue(valueOrObservable, options) {
1976
+ if (isObservable(valueOrObservable)) {
1977
+ return valueOrObservable.subscribe((value) =>
1978
+ // TODO : refactor RxapFormGroup to typed FormGroup
1979
+ super.patchValue(value, options));
1980
+ }
1981
+ this._patchValue(valueOrObservable, options);
1817
1982
  }
1818
- get submitError() {
1819
- return this.submitError$.value;
1983
+ disabledWhile(observable, options) {
1984
+ return controlDisabledWhile(this, observable, options);
1820
1985
  }
1821
- get loading() {
1822
- return this.loading$.value;
1986
+ enabledWhile(observable, options) {
1987
+ return controlEnabledWhile(this, observable, options);
1823
1988
  }
1824
- get loaded() {
1825
- return this.loaded$.value;
1989
+ mergeValidators(validators) {
1990
+ mergeControlValidators(this, validators);
1826
1991
  }
1827
- get loadingError() {
1828
- return this.loadingError$.value;
1992
+ mergeAsyncValidators(validators) {
1993
+ this.setAsyncValidators([
1994
+ ...coerceArray(this.asyncValidator),
1995
+ ...coerceArray(validators),
1996
+ ]);
1997
+ this.updateValueAndValidity();
1829
1998
  }
1830
- set useFormDefinition(value) {
1831
- if (value) {
1832
- this._formDefinition = value;
1833
- this.form = value.rxapFormGroup;
1834
- }
1999
+ markAsTouched(opts) {
2000
+ super.markAsTouched(opts);
2001
+ this.touchChanges.next(true);
1835
2002
  }
1836
- get formDefinition() {
1837
- return this._formDefinition;
2003
+ markAsUntouched(opts) {
2004
+ super.markAsUntouched(opts);
2005
+ this.touchChanges.next(false);
1838
2006
  }
1839
- constructor(cdr, formDefinition = null,
1840
- // skip self, bc the token is set to null
1841
- submitMethod = null,
1842
- // skip self, bc the token is set to null
1843
- loadMethod = null,
1844
- // skip self, bc the token is set to null
1845
- loadFailedMethod = null,
1846
- // skip self, bc the token is set to null
1847
- loadSuccessfulMethod = null,
1848
- // skip self, bc the token is set to null
1849
- submitFailedMethod = null,
1850
- // skip self, bc the token is set to null
1851
- submitSuccessfulMethod = null,
1852
- // skip self, bc the token is set to null
1853
- formDefinitionBuilder = null, loadingIndicatorService = null, context = null, initial = null) {
1854
- super([], []);
1855
- this.cdr = cdr;
1856
- this.formDefinitionBuilder = formDefinitionBuilder;
1857
- this.loadingIndicatorService = loadingIndicatorService;
1858
- this.initial = model(null, ...(ngDevMode ? [{ debugName: "initial" }] : /* istanbul ignore next */ []));
1859
- this.context = model(null, ...(ngDevMode ? [{ debugName: "context" }] : /* istanbul ignore next */ []));
1860
- /**
1861
- * Emits when the submit method is executed without errors. The result of the
1862
- * submit method is passed as event object.
1863
- *
1864
- * If no submit method is defined then emit after the submit button
1865
- * is clicked.
1866
- */
1867
- this.rxapSubmit = new EventEmitter();
1868
- this.invalidSubmit = new EventEmitter();
1869
- // eslint-disable-next-line @angular-eslint/no-output-rename
1870
- this.submitSuccessful$ = new EventEmitter();
1871
- this.submitting$ = new ToggleSubject();
1872
- this.submitError$ = new BehaviorSubject(null);
1873
- this.loading$ = new ToggleSubject();
1874
- this.loaded$ = new ToggleSubject();
1875
- this.loadingError$ = new BehaviorSubject(null);
1876
- this.submitMethod = null;
1877
- this.loadMethod = null;
1878
- this.loadFailedMethod = null;
1879
- this.loadSuccessfulMethod = null;
1880
- this.submitFailedMethod = null;
1881
- this.submitSuccessfulMethod = null;
1882
- this._autoSubmitSubscription = new Subscription();
1883
- this.submitMethod = submitMethod ?? this.submitMethod;
1884
- this.loadMethod = loadMethod ?? this.loadMethod;
1885
- this.loadFailedMethod = loadFailedMethod ?? this.loadFailedMethod;
1886
- this.loadSuccessfulMethod = loadSuccessfulMethod ?? this.loadSuccessfulMethod;
1887
- this.submitFailedMethod = submitFailedMethod ?? this.submitFailedMethod;
1888
- this.submitSuccessfulMethod = submitSuccessfulMethod ?? this.submitSuccessfulMethod;
1889
- if (!formDefinition && formDefinitionBuilder) {
1890
- formDefinition = formDefinitionBuilder.build();
1891
- }
1892
- if (formDefinition) {
1893
- this._formDefinition = formDefinition;
1894
- this.form = formDefinition.rxapFormGroup;
1895
- }
1896
- this.loadingIndicatorService?.attachLoading(this.loading$);
1897
- this.loadingIndicatorService?.attachLoading(this.submitting$);
1898
- if (context) {
1899
- this.context.set(context);
1900
- }
1901
- if (initial && typeof initial === 'object' && !Array.isArray(initial)) {
1902
- this.initial.set(initial);
1903
- }
2007
+ markAsPristine(opts) {
2008
+ super.markAsPristine(opts);
2009
+ this.dirtyChanges.next(false);
1904
2010
  }
1905
- ngOnChanges(changes) {
1906
- super.ngOnChanges(changes);
1907
- const formChange = changes['form'];
1908
- if (formChange && !formChange.firstChange) {
1909
- this.loadInitialState(formChange.currentValue);
1910
- }
2011
+ markAsDirty(opts) {
2012
+ super.markAsDirty(opts);
2013
+ this.dirtyChanges.next(true);
1911
2014
  }
1912
- ngOnInit() {
1913
- if (!this._formDefinition) {
1914
- // TODO : replace with rxap error
1915
- throw new Error('The form definition instance is not defined');
1916
- }
1917
- if (!this.form) {
1918
- // TODO : replace with rxap error
1919
- throw new Error('The form instance is not defined');
1920
- }
1921
- this.loadInitialState(this.form);
1922
- function HasNgOnInitMethod(obj) {
1923
- return obj && typeof obj.ngOnInit === 'function';
1924
- }
1925
- if (HasNgOnInitMethod(this._formDefinition)) {
1926
- this._formDefinition.ngOnInit();
1927
- }
1928
- if (this._formDefinition.rxapMetadata.autoSubmit) {
1929
- const debounce = typeof this._formDefinition.rxapMetadata.autoSubmit === 'number'
1930
- ? this._formDefinition.rxapMetadata.autoSubmit
1931
- : 5000;
1932
- this._autoSubmitSubscription = this
1933
- .form
1934
- .valueChanges
1935
- .pipe(debounceTime(debounce), filter(() => this.form.valid), tap((value) => {
1936
- if (isDevMode()) {
1937
- console.debug(`Auto submit form '${this._formDefinition.rxapMetadata.id}'`, value);
1938
- }
1939
- }), tap(() => this.submit()))
1940
- .subscribe();
1941
- }
2015
+ markAllAsDirty() {
2016
+ markAllDirty(this);
1942
2017
  }
1943
- onSubmit($event) {
1944
- $event.preventDefault();
1945
- super.onSubmit($event);
1946
- if (this.form.valid) {
1947
- this.submit();
1948
- }
1949
- else {
1950
- // eslint-disable-next-line no-inner-declarations
1951
- function reduceErrors(control, errors = {}) {
1952
- if (control.invalid) {
1953
- if (control.controls) {
1954
- if (Array.isArray(control.controls)) {
1955
- const errorList = [];
1956
- for (const item of control.controls) {
1957
- errorList.push(reduceErrors(item));
1958
- }
1959
- errors[control.controlId] = errorList;
1960
- }
1961
- else {
1962
- const innerErrors = {};
1963
- for (const child of Object.values(control.controls)) {
1964
- reduceErrors(child, innerErrors);
1965
- }
1966
- errors[control.controlId] = innerErrors;
1967
- }
1968
- }
1969
- else {
1970
- if (control.errors) {
1971
- errors[control.controlId] = control.errors;
1972
- }
1973
- }
1974
- }
1975
- return errors;
1976
- }
1977
- if (isDevMode()) {
1978
- console.log('Form submit is not valid for: ' + this.form.controlId, this.form.errors);
1979
- // eslint-disable-next-line no-inner-declarations
1980
- function printErrorControls(control) {
1981
- if (!control.valid) {
1982
- console.group(control.controlId);
1983
- if (control.controls) {
1984
- if (Array.isArray(control.controls)) {
1985
- for (let i = 0; i < control.controls.length; i++) {
1986
- const child = control.controls[i];
1987
- if (!child.valid) {
1988
- console.group(`index: ${i}`);
1989
- printErrorControls(child);
1990
- console.groupEnd();
1991
- }
1992
- }
1993
- }
1994
- else {
1995
- for (const child of Object.values(control.controls)) {
1996
- printErrorControls(child);
1997
- }
1998
- }
1999
- }
2000
- else {
2001
- if (control.errors) {
2002
- for (const [key, value] of Object.entries(control.errors)) {
2003
- console.group(key);
2004
- console.log(value);
2005
- console.groupEnd();
2006
- }
2007
- }
2008
- console.log('value: ', control.value);
2009
- }
2010
- console.groupEnd();
2011
- }
2012
- }
2013
- printErrorControls(this.form);
2014
- }
2015
- this.invalidSubmit.emit(reduceErrors(this.form));
2018
+ markAllAsPristine() {
2019
+ markAllPristine(this);
2020
+ }
2021
+ markAllAsUntouched() {
2022
+ markAllUntouched(this);
2023
+ }
2024
+ reset(formState, options) {
2025
+ super.reset(formState, options);
2026
+ }
2027
+ setValidators(newValidator, updateValueAndValidity = true) {
2028
+ super.setValidators(newValidator);
2029
+ if (updateValueAndValidity) {
2030
+ super.updateValueAndValidity();
2016
2031
  }
2017
- return false;
2018
2032
  }
2019
- loadInitialState(form) {
2020
- const initial = this.initial();
2021
- if (initial && typeof initial === 'object' && !Array.isArray(initial)) {
2022
- if (isDevMode()) {
2023
- console.log('use the value from input initial');
2024
- }
2025
- form.patchValue(initial, { setInitialValue: true });
2033
+ setAsyncValidators(newValidator, updateValueAndValidity = true) {
2034
+ super.setAsyncValidators(newValidator);
2035
+ if (updateValueAndValidity) {
2036
+ super.updateValueAndValidity();
2026
2037
  }
2027
- else {
2028
- if (this.loadMethod) {
2029
- this.loading$.enable();
2030
- try {
2031
- const resultOrPromise = this.loadMethod.call({ context: this.context(), initial: this.initial() });
2032
- if (isPromise(resultOrPromise)) {
2033
- resultOrPromise
2034
- .then((value) => {
2035
- form.patchValue(value, { setInitialValue: true });
2036
- this.loaded$.enable();
2037
- this.loadSuccessful(value);
2038
- })
2039
- .catch((error) => {
2040
- this.loadingError$.next(error);
2041
- this.loadFailed(error);
2042
- })
2043
- .finally(() => {
2044
- this.loading$.disable();
2045
- this.cdr.detectChanges();
2046
- });
2047
- }
2048
- else if (isObject(resultOrPromise)) {
2049
- form.patchValue(resultOrPromise, { setInitialValue: true });
2050
- this.loaded$.enable();
2051
- this.loadSuccessful(resultOrPromise);
2052
- this.loading$.disable();
2053
- }
2054
- }
2055
- catch (error) {
2056
- this.loaded$.disable();
2057
- this.loadingError$.next(error);
2058
- this.loadFailed(error);
2059
- this.loading$.disable();
2038
+ }
2039
+ validateOn(observableValidation) {
2040
+ return validateControlOn(this, observableValidation);
2041
+ }
2042
+ hasError(errorCode, path) {
2043
+ return super.hasError(errorCode, path);
2044
+ }
2045
+ setErrors(errors, opts = {}) {
2046
+ return super.setErrors(errors, opts);
2047
+ }
2048
+ getError(errorCode, path) {
2049
+ return super.getError(errorCode, path);
2050
+ }
2051
+ hasErrorAndTouched(error, ...path) {
2052
+ return hasErrorAndTouched(this, error, ...path);
2053
+ }
2054
+ hasErrorAndDirty(error, ...path) {
2055
+ return hasErrorAndDirty(this, error, ...path);
2056
+ }
2057
+ setEnable(enable = true, opts) {
2058
+ enableControl(this, enable, opts);
2059
+ }
2060
+ setDisable(disable = true, opts) {
2061
+ disableControl(this, disable, opts);
2062
+ }
2063
+ }
2064
+
2065
+ class RxapFormControl extends UntypedFormControl {
2066
+ /**
2067
+ * @internal
2068
+ */
2069
+ get rxapFormDefinition() {
2070
+ return this.parent.rxapFormDefinition;
2071
+ }
2072
+ get initialState() {
2073
+ return this._initialState;
2074
+ }
2075
+ get readonly() {
2076
+ return this.parent?.readonly ?? this._readonly;
2077
+ }
2078
+ set readonly(value) {
2079
+ this._readonly = value;
2080
+ this.stateChanges.next();
2081
+ }
2082
+ get controlPath() {
2083
+ const parent = this.parent;
2084
+ if (parent) {
2085
+ if (parent.controlPath) {
2086
+ if (parent === this.root) {
2087
+ return this.controlId;
2060
2088
  }
2061
- }
2062
- else {
2063
- if (isDevMode()) {
2064
- console.warn('The form loading method is not defined for: ' + this.form.controlId);
2089
+ else {
2090
+ return [parent.controlPath, this.controlId].join('.');
2065
2091
  }
2066
- this.loaded$.enable();
2067
2092
  }
2068
2093
  }
2094
+ return this.controlId;
2069
2095
  }
2070
- loadSuccessful(value) {
2071
- if (this.loadSuccessfulMethod) {
2072
- this.loadSuccessfulMethod.call(value);
2073
- }
2074
- else if (isDevMode()) {
2075
- console.warn('The load successful is not defined for: ' + this.form.controlId);
2096
+ get fullControlPath() {
2097
+ const parent = this.parent;
2098
+ if (parent) {
2099
+ if (parent.fullControlPath) {
2100
+ return [parent.fullControlPath, this.controlId].join('.');
2101
+ }
2076
2102
  }
2103
+ return this.controlId;
2077
2104
  }
2078
- loadFailed(error) {
2079
- console.debug('Load Error:', error);
2080
- console.error('Load Error:', error.message);
2081
- if (this.loadFailedMethod) {
2082
- this.loadFailedMethod?.call(error);
2105
+ constructor(formState, options) {
2106
+ super(formState, options);
2107
+ this._readonly = false;
2108
+ this.touchChanges = new Subject();
2109
+ this.dirtyChanges = new Subject();
2110
+ this.touch$ = this.touchChanges
2111
+ .asObservable()
2112
+ .pipe(distinctUntilChanged());
2113
+ this.dirty$ = this.dirtyChanges
2114
+ .asObservable()
2115
+ .pipe(distinctUntilChanged());
2116
+ this.value$ = controlValueChanges$(this);
2117
+ this.disabled$ = controlDisabled$(this);
2118
+ this.enabled$ = controlEnabled$(this);
2119
+ this.status$ = controlStatusChanges$(this);
2120
+ this.errors$ = controlErrorChanges$(this);
2121
+ this._onSetValue = [];
2122
+ this.stateChanges = new Subject();
2123
+ this.readonly$ = controlReadonly$(this);
2124
+ this.controlId = options.controlId;
2125
+ if (options.disabled) {
2126
+ this.disable({ emitEvent: false });
2083
2127
  }
2084
- else if (isDevMode()) {
2085
- console.warn('The form loading failed for: ' + this.form.controlId);
2128
+ if (options.readonly) {
2129
+ this.readonly = true;
2086
2130
  }
2131
+ this._initialState = formState;
2087
2132
  }
2088
- getSubmitValue() {
2089
- let value = undefined;
2090
- if (typeof this._formDefinition['getSubmitValue'] === 'function') {
2091
- value = this._formDefinition.getSubmitValue();
2092
- }
2093
- else if (typeof this._formDefinition['toJSON'] === 'function') {
2094
- value = this._formDefinition.toJSON();
2133
+ setValue(valueOrObservable, options) {
2134
+ if (isObservable(valueOrObservable)) {
2135
+ return valueOrObservable.subscribe((value) => {
2136
+ super.setValue(value, options);
2137
+ this._onSetValue.forEach((setValueFn) => setValueFn(value, options));
2138
+ });
2095
2139
  }
2096
- value = value ?? clone(this.form.value);
2097
- return value;
2140
+ super.setValue(valueOrObservable, options);
2141
+ this._onSetValue.forEach((setValueFn) => setValueFn(valueOrObservable, options));
2098
2142
  }
2099
- submit() {
2100
- const value = this.getSubmitValue();
2101
- if (this.submitMethod) {
2102
- Reflect.set(this, 'submitted', false);
2103
- this.submitting$.enable();
2104
- this.submitError$.next(null);
2105
- try {
2106
- const resultOrPromise = this.submitMethod.call(value, this.context(), this.initial());
2107
- if (isPromise(resultOrPromise)) {
2108
- resultOrPromise
2109
- .then((result) => {
2110
- Reflect.set(this, 'submitted', true);
2111
- this.rxapSubmit.emit(result);
2112
- this.submitSuccessful(result);
2113
- })
2114
- .catch((error) => {
2115
- this.submitError$.next(error);
2116
- this.submitFailed(error);
2117
- })
2118
- .finally(() => {
2119
- this.submitting$.disable();
2120
- this.cdr.detectChanges();
2121
- });
2122
- }
2123
- else {
2124
- Reflect.set(this, 'submitted', true);
2125
- this.rxapSubmit.emit(resultOrPromise);
2126
- this.submitSuccessful(resultOrPromise);
2127
- this.submitting$.disable();
2143
+ patchValue(valueOrObservable, options) {
2144
+ if (isObservable(valueOrObservable)) {
2145
+ return valueOrObservable.subscribe(value => {
2146
+ super.patchValue(value, options);
2147
+ if (options?.setInitialValue) {
2148
+ this._initialState = value;
2128
2149
  }
2129
- }
2130
- catch (error) {
2131
- this.submitting$.disable();
2132
- this.submitError$.next(error);
2133
- this.submitFailed(error);
2134
- }
2150
+ });
2135
2151
  }
2136
- else {
2137
- if (isDevMode()) {
2138
- console.warn('The form submit method is not defined for: ' + this.form.controlId);
2139
- }
2140
- this.rxapSubmit.emit(value);
2141
- this.submitSuccessful(value);
2152
+ super.patchValue(valueOrObservable, options);
2153
+ if (options?.setInitialValue) {
2154
+ this._initialState = valueOrObservable;
2142
2155
  }
2143
2156
  }
2144
- submitFailed(error) {
2145
- console.debug('Submit Error:', error);
2146
- console.error('Submit Error:', error.message);
2147
- if (this.submitFailedMethod) {
2148
- this.submitFailedMethod.call(error);
2149
- }
2150
- else if (isDevMode()) {
2151
- console.warn('The form submit failed method is not defined for: ' +
2152
- this.form.controlId);
2153
- }
2157
+ disabledWhile(observable, options) {
2158
+ return controlDisabledWhile(this, observable, options);
2154
2159
  }
2155
- submitSuccessful(value) {
2156
- this.submitSuccessful$.next(value);
2157
- if (this.submitSuccessfulMethod) {
2158
- this.submitSuccessfulMethod.call(value);
2159
- }
2160
- else if (isDevMode()) {
2161
- console.warn('The form submit successful method is not defined for: ' +
2162
- this.form.controlId);
2160
+ enabledWhile(observable, options) {
2161
+ return controlEnabledWhile(this, observable, options);
2162
+ }
2163
+ mergeValidators(validators) {
2164
+ mergeControlValidators(this, validators);
2165
+ }
2166
+ mergeAsyncValidators(validators) {
2167
+ this.setAsyncValidators([
2168
+ // TODO : remove 'as any' if solution for the type overwrite issue is found (above)
2169
+ this.asyncValidator,
2170
+ ...coerceArray(validators),
2171
+ ]);
2172
+ this.updateValueAndValidity();
2173
+ }
2174
+ markAsTouched(opts) {
2175
+ super.markAsTouched(opts);
2176
+ this.touchChanges.next(true);
2177
+ }
2178
+ markAsUntouched(opts) {
2179
+ super.markAsUntouched(opts);
2180
+ this.touchChanges.next(false);
2181
+ }
2182
+ markAsPristine(opts) {
2183
+ super.markAsPristine(opts);
2184
+ this.dirtyChanges.next(false);
2185
+ }
2186
+ markAsDirty(opts) {
2187
+ super.markAsDirty(opts);
2188
+ this.dirtyChanges.next(true);
2189
+ }
2190
+ markAllAsDirty() {
2191
+ this.markAsDirty({ onlySelf: true });
2192
+ }
2193
+ reset(formState, options) {
2194
+ const newState = formState ?? this.initialState;
2195
+ if (typeof newState === 'function') {
2196
+ super.reset(newState(), options);
2197
+ }
2198
+ else {
2199
+ super.reset(newState, options);
2163
2200
  }
2164
2201
  }
2165
- ngOnDestroy() {
2166
- super.ngOnDestroy();
2167
- this._autoSubmitSubscription?.unsubscribe();
2168
- function HasNgOnDestroyMethod(obj) {
2169
- return obj && typeof obj.ngOnDestroy === 'function';
2202
+ setValidators(newValidator, updateValueAndValidity = true) {
2203
+ super.setValidators(newValidator);
2204
+ if (updateValueAndValidity) {
2205
+ super.updateValueAndValidity();
2170
2206
  }
2171
- if (HasNgOnDestroyMethod(this._formDefinition)) {
2172
- this._formDefinition.ngOnDestroy();
2207
+ }
2208
+ setAsyncValidators(newValidator, updateValueAndValidity = true) {
2209
+ super.setAsyncValidators(newValidator);
2210
+ if (updateValueAndValidity) {
2211
+ super.updateValueAndValidity();
2173
2212
  }
2174
2213
  }
2175
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormDirective, deps: [{ token: ChangeDetectorRef }, { token: RXAP_FORM_DEFINITION, optional: true }, { token: RXAP_FORM_SUBMIT_METHOD, optional: true, skipSelf: true }, { token: RXAP_FORM_LOAD_METHOD, optional: true, skipSelf: true }, { token: RXAP_FORM_LOAD_FAILED_METHOD, optional: true, skipSelf: true }, { token: RXAP_FORM_LOAD_SUCCESSFUL_METHOD, optional: true, skipSelf: true }, { token: RXAP_FORM_SUBMIT_FAILED_METHOD, optional: true, skipSelf: true }, { token: RXAP_FORM_SUBMIT_SUCCESSFUL_METHOD, optional: true, skipSelf: true }, { token: RXAP_FORM_DEFINITION_BUILDER, optional: true, skipSelf: true }, { token: LoadingIndicatorService, optional: true }, { token: RXAP_FORM_CONTEXT, optional: true }, { token: RXAP_FORM_INITIAL_STATE, optional: true }], target: i0.ɵɵFactoryTarget.Directive }); }
2176
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.9", type: FormDirective, isStandalone: true, selector: "form[rxapForm]:not([formGroup]):not([ngForm]),rxap-form,form[rxapForm]", inputs: { initial: { classPropertyName: "initial", publicName: "initial", isSignal: true, isRequired: false, transformFunction: null }, context: { classPropertyName: "context", publicName: "context", isSignal: true, isRequired: false, transformFunction: null }, useFormDefinition: { classPropertyName: "useFormDefinition", publicName: "rxapForm", isSignal: false, isRequired: false, transformFunction: null }, submitMethod: { classPropertyName: "submitMethod", publicName: "submitMethod", isSignal: false, isRequired: false, transformFunction: null }, loadMethod: { classPropertyName: "loadMethod", publicName: "loadMethod", isSignal: false, isRequired: false, transformFunction: null }, loadFailedMethod: { classPropertyName: "loadFailedMethod", publicName: "loadFailedMethod", isSignal: false, isRequired: false, transformFunction: null }, loadSuccessfulMethod: { classPropertyName: "loadSuccessfulMethod", publicName: "loadSuccessfulMethod", isSignal: false, isRequired: false, transformFunction: null }, submitFailedMethod: { classPropertyName: "submitFailedMethod", publicName: "submitFailedMethod", isSignal: false, isRequired: false, transformFunction: null }, submitSuccessfulMethod: { classPropertyName: "submitSuccessfulMethod", publicName: "submitSuccessfulMethod", isSignal: false, isRequired: false, transformFunction: null } }, outputs: { ngSubmit: "ngSubmit", initial: "initialChange", context: "contextChange", rxapSubmit: "rxapSubmit", invalidSubmit: "invalidSubmit", submitSuccessful$: "submitSuccessful" }, host: { listeners: { "reset": "onReset()" }, properties: { "class.rxap-submitting": "this.submitting", "class.rxap-submit-error": "this.submitError", "class.rxap-loading": "this.loading", "class.rxap-loaded": "this.loaded", "class.rxap-loading-error": "this.loadingError" } }, providers: [
2177
- {
2178
- provide: ControlContainer,
2179
- // ignore coverage
2180
- useExisting: forwardRef(() => FormDirective),
2181
- },
2182
- // region form provider clear
2183
- // form provider that are directly associated with the current form
2184
- // are cleared to prevent that inner forms can access this providers
2185
- // Example: The parent form has a submit method provider and the inner should
2186
- // not have a submit method provider. If the parent submit method provider is
2187
- // not cleared then the inner form uses the parent submit method provider on
2188
- // submit
2189
- {
2190
- provide: RXAP_FORM_SUBMIT_METHOD,
2191
- useValue: null,
2192
- },
2193
- {
2194
- provide: RXAP_FORM_LOAD_METHOD,
2195
- useValue: null,
2196
- },
2197
- {
2198
- provide: RXAP_FORM_LOAD_FAILED_METHOD,
2199
- useValue: null,
2200
- },
2201
- {
2202
- provide: RXAP_FORM_LOAD_SUCCESSFUL_METHOD,
2203
- useValue: null,
2204
- },
2205
- {
2206
- provide: RXAP_FORM_SUBMIT_FAILED_METHOD,
2207
- useValue: null,
2208
- },
2209
- {
2210
- provide: RXAP_FORM_SUBMIT_SUCCESSFUL_METHOD,
2211
- useValue: null,
2212
- },
2213
- {
2214
- provide: RXAP_FORM_DEFINITION_BUILDER,
2215
- useValue: null,
2216
- },
2217
- // endregion
2218
- ], exportAs: ["rxapForm"], usesInheritance: true, usesOnChanges: true, ngImport: i0 }); }
2219
- }
2220
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormDirective, decorators: [{
2221
- type: Directive,
2222
- args: [{
2223
- selector: 'form[rxapForm]:not([formGroup]):not([ngForm]),rxap-form,form[rxapForm]',
2224
- providers: [
2225
- {
2226
- provide: ControlContainer,
2227
- // ignore coverage
2228
- useExisting: forwardRef(() => FormDirective),
2229
- },
2230
- // region form provider clear
2231
- // form provider that are directly associated with the current form
2232
- // are cleared to prevent that inner forms can access this providers
2233
- // Example: The parent form has a submit method provider and the inner should
2234
- // not have a submit method provider. If the parent submit method provider is
2235
- // not cleared then the inner form uses the parent submit method provider on
2236
- // submit
2237
- {
2238
- provide: RXAP_FORM_SUBMIT_METHOD,
2239
- useValue: null,
2240
- },
2241
- {
2242
- provide: RXAP_FORM_LOAD_METHOD,
2243
- useValue: null,
2244
- },
2245
- {
2246
- provide: RXAP_FORM_LOAD_FAILED_METHOD,
2247
- useValue: null,
2248
- },
2249
- {
2250
- provide: RXAP_FORM_LOAD_SUCCESSFUL_METHOD,
2251
- useValue: null,
2252
- },
2253
- {
2254
- provide: RXAP_FORM_SUBMIT_FAILED_METHOD,
2255
- useValue: null,
2256
- },
2257
- {
2258
- provide: RXAP_FORM_SUBMIT_SUCCESSFUL_METHOD,
2259
- useValue: null,
2260
- },
2261
- {
2262
- provide: RXAP_FORM_DEFINITION_BUILDER,
2263
- useValue: null,
2264
- },
2265
- // endregion
2266
- ],
2267
- host: { '(reset)': 'onReset()' },
2268
- // eslint-disable-next-line @angular-eslint/no-outputs-metadata-property
2269
- outputs: ['ngSubmit'],
2270
- exportAs: 'rxapForm',
2271
- standalone: true,
2272
- }]
2273
- }], ctorParameters: () => [{ type: i0.ChangeDetectorRef, decorators: [{
2274
- type: Inject,
2275
- args: [ChangeDetectorRef]
2276
- }] }, { type: undefined, decorators: [{
2277
- type: Optional
2278
- }, {
2279
- type: Inject,
2280
- args: [RXAP_FORM_DEFINITION]
2281
- }] }, { type: undefined, decorators: [{
2282
- type: SkipSelf
2283
- }, {
2284
- type: Optional
2285
- }, {
2286
- type: Inject,
2287
- args: [RXAP_FORM_SUBMIT_METHOD]
2288
- }] }, { type: undefined, decorators: [{
2289
- type: SkipSelf
2290
- }, {
2291
- type: Optional
2292
- }, {
2293
- type: Inject,
2294
- args: [RXAP_FORM_LOAD_METHOD]
2295
- }] }, { type: undefined, decorators: [{
2296
- type: SkipSelf
2297
- }, {
2298
- type: Optional
2299
- }, {
2300
- type: Inject,
2301
- args: [RXAP_FORM_LOAD_FAILED_METHOD]
2302
- }] }, { type: undefined, decorators: [{
2303
- type: SkipSelf
2304
- }, {
2305
- type: Optional
2306
- }, {
2307
- type: Inject,
2308
- args: [RXAP_FORM_LOAD_SUCCESSFUL_METHOD]
2309
- }] }, { type: undefined, decorators: [{
2310
- type: SkipSelf
2311
- }, {
2312
- type: Optional
2313
- }, {
2314
- type: Inject,
2315
- args: [RXAP_FORM_SUBMIT_FAILED_METHOD]
2316
- }] }, { type: undefined, decorators: [{
2317
- type: SkipSelf
2318
- }, {
2319
- type: Optional
2320
- }, {
2321
- type: Inject,
2322
- args: [RXAP_FORM_SUBMIT_SUCCESSFUL_METHOD]
2323
- }] }, { type: RxapFormBuilder, decorators: [{
2324
- type: SkipSelf
2325
- }, {
2326
- type: Optional
2327
- }, {
2328
- type: Inject,
2329
- args: [RXAP_FORM_DEFINITION_BUILDER]
2330
- }] }, { type: i2.LoadingIndicatorService, decorators: [{
2331
- type: Optional
2332
- }, {
2333
- type: Inject,
2334
- args: [LoadingIndicatorService]
2335
- }] }, { type: undefined, decorators: [{
2336
- type: Optional
2337
- }, {
2338
- type: Inject,
2339
- args: [RXAP_FORM_CONTEXT]
2340
- }] }, { type: undefined, decorators: [{
2341
- type: Optional
2342
- }, {
2343
- type: Inject,
2344
- args: [RXAP_FORM_INITIAL_STATE]
2345
- }] }], propDecorators: { initial: [{ type: i0.Input, args: [{ isSignal: true, alias: "initial", required: false }] }, { type: i0.Output, args: ["initialChange"] }], context: [{ type: i0.Input, args: [{ isSignal: true, alias: "context", required: false }] }, { type: i0.Output, args: ["contextChange"] }], rxapSubmit: [{
2346
- type: Output
2347
- }], invalidSubmit: [{
2348
- type: Output
2349
- }], submitSuccessful$: [{
2350
- type: Output,
2351
- args: ['submitSuccessful']
2352
- }], submitting: [{
2353
- type: HostBinding,
2354
- args: ['class.rxap-submitting']
2355
- }], submitError: [{
2356
- type: HostBinding,
2357
- args: ['class.rxap-submit-error']
2358
- }], loading: [{
2359
- type: HostBinding,
2360
- args: ['class.rxap-loading']
2361
- }], loaded: [{
2362
- type: HostBinding,
2363
- args: ['class.rxap-loaded']
2364
- }], loadingError: [{
2365
- type: HostBinding,
2366
- args: ['class.rxap-loading-error']
2367
- }], useFormDefinition: [{
2368
- type: Input,
2369
- args: ['rxapForm']
2370
- }], submitMethod: [{
2371
- type: Input
2372
- }], loadMethod: [{
2373
- type: Input
2374
- }], loadFailedMethod: [{
2375
- type: Input
2376
- }], loadSuccessfulMethod: [{
2377
- type: Input
2378
- }], submitFailedMethod: [{
2379
- type: Input
2380
- }], submitSuccessfulMethod: [{
2381
- type: Input
2382
- }] } });
2383
-
2384
- class FormLoadedDirective {
2385
- constructor(formDirective, template, viewContainerRef) {
2386
- this.formDirective = formDirective;
2387
- this.template = template;
2388
- this.viewContainerRef = viewContainerRef;
2214
+ validateOn(observableValidation) {
2215
+ return validateControlOn(this, observableValidation);
2389
2216
  }
2390
- ngAfterViewInit() {
2391
- this.subscription = this.formDirective.loaded$.pipe(distinctUntilChanged(), tap(loading => {
2392
- this.viewContainerRef.clear();
2393
- if (loading) {
2394
- this.viewContainerRef.createEmbeddedView(this.template);
2395
- }
2396
- })).subscribe();
2217
+ getError(errorCode) {
2218
+ return super.getError(errorCode);
2397
2219
  }
2398
- ngOnDestroy() {
2399
- this.subscription?.unsubscribe();
2220
+ hasError(errorCode) {
2221
+ return super.hasError(errorCode);
2222
+ }
2223
+ setErrors(errors, opts = {}) {
2224
+ return super.setErrors(errors, opts);
2225
+ }
2226
+ setError(key, value, opts = {}) {
2227
+ super.setErrors({ [key]: value }, opts);
2228
+ }
2229
+ hasErrorAndTouched(error) {
2230
+ return hasErrorAndTouched(this, error);
2231
+ }
2232
+ hasErrorAndDirty(error) {
2233
+ return hasErrorAndDirty(this, error);
2234
+ }
2235
+ setEnable(enable = true, opts) {
2236
+ enableControl(this, enable, opts);
2237
+ }
2238
+ setDisable(disable = true, opts) {
2239
+ disableControl(this, disable, opts);
2240
+ }
2241
+ registerOnSetValue(setValueFn) {
2242
+ this._onSetValue.push(setValueFn);
2400
2243
  }
2401
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormLoadedDirective, deps: [{ token: FormDirective }, { token: TemplateRef }, { token: ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive }); }
2402
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: FormLoadedDirective, isStandalone: true, selector: "[rxapFormLoaded]", ngImport: i0 }); }
2403
2244
  }
2404
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormLoadedDirective, decorators: [{
2405
- type: Directive,
2406
- args: [{
2407
- selector: '[rxapFormLoaded]',
2408
- standalone: true,
2409
- }]
2410
- }], ctorParameters: () => [{ type: FormDirective, decorators: [{
2411
- type: Inject,
2412
- args: [FormDirective]
2413
- }] }, { type: i0.TemplateRef, decorators: [{
2414
- type: Inject,
2415
- args: [TemplateRef]
2416
- }] }, { type: i0.ViewContainerRef, decorators: [{
2417
- type: Inject,
2418
- args: [ViewContainerRef]
2419
- }] }] });
2420
2245
 
2421
- class FormLoadingErrorDirective {
2422
- constructor(formDirective, template, viewContainerRef) {
2423
- this.formDirective = formDirective;
2424
- this.template = template;
2425
- this.viewContainerRef = viewContainerRef;
2246
+ /* eslint-disable @typescript-eslint/ban-types */
2247
+ class FormArrayControlManager {
2248
+ constructor(form, controlId) {
2249
+ this.form = form;
2250
+ this.controlId = controlId;
2426
2251
  }
2427
- ngAfterViewInit() {
2428
- this.subscription = this.formDirective.loadingError$.pipe(tap(error => {
2429
- this.viewContainerRef.clear();
2430
- if (error !== null) {
2431
- this.viewContainerRef.createEmbeddedView(this.template, { $implicit: error });
2432
- }
2433
- })).subscribe();
2252
+ inserted(index, controlOrDefinition) {
2253
+ const controlContainer = this.form[this.controlId];
2254
+ if (Array.isArray(controlContainer)) {
2255
+ controlContainer.splice(index, 0, controlOrDefinition);
2256
+ }
2257
+ else {
2258
+ throw new Error('Could not register inserted control or definition. The control id does not points to an array of control or definition instance!');
2259
+ }
2434
2260
  }
2435
- ngOnDestroy() {
2436
- this.subscription?.unsubscribe();
2261
+ removed(index) {
2262
+ const controlContainer = this.form[this.controlId];
2263
+ if (Array.isArray(controlContainer)) {
2264
+ controlContainer.splice(index, 1);
2265
+ }
2266
+ else {
2267
+ throw new Error('Could not register inserted control or definition. The control id does not points to an array of control or definition instance!');
2268
+ }
2437
2269
  }
2438
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormLoadingErrorDirective, deps: [{ token: FormDirective }, { token: TemplateRef }, { token: ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive }); }
2439
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: FormLoadingErrorDirective, isStandalone: true, selector: "[rxapFormLoadingError]", ngImport: i0 }); }
2440
2270
  }
2441
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormLoadingErrorDirective, decorators: [{
2442
- type: Directive,
2443
- args: [{
2444
- selector: '[rxapFormLoadingError]',
2445
- standalone: true,
2446
- }]
2447
- }], ctorParameters: () => [{ type: FormDirective, decorators: [{
2448
- type: Inject,
2449
- args: [FormDirective]
2450
- }] }, { type: i0.TemplateRef, decorators: [{
2451
- type: Inject,
2452
- args: [TemplateRef]
2453
- }] }, { type: i0.ViewContainerRef, decorators: [{
2454
- type: Inject,
2455
- args: [ViewContainerRef]
2456
- }] }] });
2457
-
2458
- class FormLoadingDirective {
2459
- constructor(formDirective, template, viewContainerRef) {
2460
- this.formDirective = formDirective;
2461
- this.template = template;
2462
- this.viewContainerRef = viewContainerRef;
2271
+ class RxapFormBuilder {
2272
+ constructor(definition, injector = Injector.NULL, providers = []) {
2273
+ this.definition = definition;
2274
+ this.injector = injector;
2275
+ this.formArrayGroups = this.extractArrayGroups();
2276
+ this.formArrayControls = this.extractArrayControls();
2277
+ this.formControls = this.extractControls();
2278
+ this.formGroups = this.extractGroups();
2279
+ this.validators = this.extractValidators();
2280
+ this.asyncValidators = this.extractAsyncValidators();
2281
+ this.controlChanges = this.extractControlChanges();
2282
+ this.controlSetValue = this.extractControlSetValue();
2283
+ const formOptions = (this.formOptions = this.extractFormOptions());
2284
+ // merge the providers from the from options with the providers from the
2285
+ // constructor. If the provider is defined in the form options and constructor
2286
+ // then the provider from the constructor will be used.
2287
+ this.providers = [...providers, ...(formOptions.providers ?? [])].filter((provider, index, self) => provider['provide'] &&
2288
+ self.findIndex((selfProvider) => selfProvider.provide &&
2289
+ selfProvider.provide === provider.provide) === index);
2463
2290
  }
2464
- ngAfterViewInit() {
2465
- this.subscription = this.formDirective.loading$.pipe(distinctUntilChanged(), tap(loading => {
2466
- this.viewContainerRef.clear();
2467
- if (loading) {
2468
- this.viewContainerRef.createEmbeddedView(this.template);
2291
+ build(state = {}, options = {}) {
2292
+ const injector = Injector.create({
2293
+ name: `rxap/form-builder/${this.formOptions.id}`,
2294
+ parent: this.injector,
2295
+ providers: this.providers,
2296
+ });
2297
+ let form;
2298
+ // don't use the notFoundValue feature of the injector.
2299
+ // if used for each call of the get method an "empty" or "fallback"
2300
+ // instance is created
2301
+ try {
2302
+ form = injector.get(this.definition);
2303
+ }
2304
+ catch (e) {
2305
+ const message = typeof e?.message === 'string' ? e.message : '';
2306
+ // Angular 21 throws a RuntimeError NG0201 ("No provider found for `X`.")
2307
+ // instead of the old NullInjectorError ("No provider for X"). Detect both.
2308
+ const isNoProvider = e?.name === 'NullInjectorError' ||
2309
+ message.includes('NG0201') ||
2310
+ message.includes('No provider');
2311
+ if (isNoProvider && message.includes(this.definition.name)) {
2312
+ if (isDevMode()) {
2313
+ console.warn(`Could not inject the definition instance. Fallback and call the constructor of the definition class: ${message}`);
2314
+ }
2315
+ form = new this.definition();
2316
+ }
2317
+ else {
2318
+ throw new Error(`Could not inject the definition instance: ${message}`);
2319
+ }
2320
+ }
2321
+ const controls = {};
2322
+ this.buildControls(state, form, controls);
2323
+ this.buildGroups(state, form, controls);
2324
+ this.buildArrayGroups(state, form, controls);
2325
+ this.buildArrayControls(state, form, controls);
2326
+ const formOptions = {
2327
+ ...this.formOptions,
2328
+ controlId: options.controlId ?? (options.id ? options.id : this.formOptions.id),
2329
+ ...options,
2330
+ };
2331
+ form.rxapFormGroup = new RxapFormGroup(controls, formOptions);
2332
+ Reflect.set(form.rxapFormGroup, '_rxapFormDefinition', form);
2333
+ form.rxapMetadata = this.formOptions;
2334
+ if (HasRxapOnInitMethod(form)) {
2335
+ form.rxapOnInit();
2336
+ }
2337
+ for (const control of Object.values(form.rxapFormGroup.controls)) {
2338
+ if (control.controlId) {
2339
+ const controlSetValueOnInit = Array.from(this.controlSetValue.get(control.controlId) ?? []).filter((controlSetValueOptions) => controlSetValueOptions.initial);
2340
+ for (const onSetValue of this.coerceToFnArray(form, controlSetValueOnInit)) {
2341
+ onSetValue(control.value, { initial: true });
2342
+ }
2469
2343
  }
2470
- })).subscribe();
2471
- }
2472
- ngOnDestroy() {
2473
- this.subscription?.unsubscribe();
2344
+ }
2345
+ return form;
2474
2346
  }
2475
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormLoadingDirective, deps: [{ token: FormDirective }, { token: TemplateRef }, { token: ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive }); }
2476
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: FormLoadingDirective, isStandalone: true, selector: "[rxapFormLoading]", ngImport: i0 }); }
2477
- }
2478
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormLoadingDirective, decorators: [{
2479
- type: Directive,
2480
- args: [{
2481
- selector: '[rxapFormLoading]',
2482
- standalone: true,
2483
- }]
2484
- }], ctorParameters: () => [{ type: FormDirective, decorators: [{
2485
- type: Inject,
2486
- args: [FormDirective]
2487
- }] }, { type: i0.TemplateRef, decorators: [{
2488
- type: Inject,
2489
- args: [TemplateRef]
2490
- }] }, { type: i0.ViewContainerRef, decorators: [{
2491
- type: Inject,
2492
- args: [ViewContainerRef]
2493
- }] }] });
2494
-
2495
- class FormResetDirective extends ConfirmClick {
2496
- constructor(formDirective) {
2497
- super();
2498
- this.formDirective = formDirective;
2499
- this.type = 'button';
2347
+ buildArrayControls(builderFormState, form, controls) {
2348
+ for (const [controlId, options] of this.formArrayControls.entries()) {
2349
+ const formState = this.coerceToArrayFormState(controlId, [], builderFormState, options.state);
2350
+ assertIsArray(formState);
2351
+ const formControls = formState.map((fs, index) => new RxapFormControl(fs, { controlId: index.toFixed(0) }));
2352
+ const manager = new FormArrayControlManager(form, controlId);
2353
+ const formArray = (formControls.rxapFormArray =
2354
+ controls[controlId] =
2355
+ new RxapFormArray(
2356
+ // TODO : add the formControlOptions property. To definition the form control options
2357
+ formControls, {
2358
+ ...options,
2359
+ controlId,
2360
+ validators: [],
2361
+ asyncValidators: [],
2362
+ controlInsertedFn: manager.inserted.bind(manager),
2363
+ controlRemovedFn: manager.removed.bind(manager),
2364
+ builder: (state, controlOptions) => new RxapFormControl(state, controlOptions),
2365
+ }));
2366
+ // TODO : add support for injectable validators
2367
+ formArray.setValidators(this.coerceToValidatorArray(form, options.validators, this.validators.get(controlId)), false);
2368
+ formArray.setAsyncValidators(this.coerceToValidatorArray(form, options.asyncValidators, this.asyncValidators.get(controlId)), false);
2369
+ Reflect.set(form, controlId, formControls);
2370
+ }
2500
2371
  }
2501
- execute() {
2502
- this.formDirective.reset();
2372
+ buildArrayGroups(builderFormState, form, controls) {
2373
+ for (const [controlId, options] of this.formArrayGroups.entries()) {
2374
+ const formState = this.coerceToArrayFormState(controlId, [], builderFormState, options.state);
2375
+ assertIsArray(formState);
2376
+ const formGroupBuilder = new RxapFormBuilder(options.definition, this.injector, this.providers);
2377
+ // TODO : add the formGroupOptions property. To definition of the form group options
2378
+ const formGroupDefinitions = formState.map((fs, index) => formGroupBuilder.build(fs, { id: index.toFixed(0) }));
2379
+ const manager = new FormArrayControlManager(form, controlId);
2380
+ const formArray = (formGroupDefinitions.rxapFormArray =
2381
+ controls[controlId] =
2382
+ new RxapFormArray(formGroupDefinitions.map((fgd) => fgd.rxapFormGroup), {
2383
+ ...options,
2384
+ builder: formGroupBuilder.build.bind(formGroupBuilder),
2385
+ controlId,
2386
+ validators: [],
2387
+ asyncValidators: [],
2388
+ controlInsertedFn: manager.inserted.bind(manager),
2389
+ controlRemovedFn: manager.removed.bind(manager),
2390
+ }));
2391
+ // TODO : add support for injectable validators
2392
+ formArray.setValidators(this.coerceToValidatorArray(form, options.validators, this.validators.get(controlId)), false);
2393
+ formArray.setAsyncValidators(this.coerceToValidatorArray(form, options.asyncValidators, this.asyncValidators.get(controlId)), false);
2394
+ Reflect.set(form, controlId, formGroupDefinitions);
2395
+ }
2503
2396
  }
2504
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormResetDirective, deps: [{ token: FormDirective }], target: i0.ɵɵFactoryTarget.Directive }); }
2505
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: FormResetDirective, isStandalone: true, selector: "[rxapFormReset]", inputs: { type: "type" }, host: { listeners: { "click": "onClick()", "confirmed": "onConfirm()" }, properties: { "type": "this.type" } }, usesInheritance: true, ngImport: i0 }); }
2506
- }
2507
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormResetDirective, decorators: [{
2508
- type: Directive,
2509
- args: [{
2510
- selector: '[rxapFormReset]',
2511
- host: {
2512
- '(click)': 'onClick()',
2513
- '(confirmed)': 'onConfirm()',
2514
- },
2515
- standalone: true,
2516
- }]
2517
- }], ctorParameters: () => [{ type: FormDirective, decorators: [{
2518
- type: Inject,
2519
- args: [FormDirective]
2520
- }] }], propDecorators: { type: [{
2521
- type: HostBinding,
2522
- args: ['type']
2523
- }, {
2524
- type: Input
2525
- }] } });
2526
-
2527
- class FormSubmitFailedDirective {
2528
- constructor(formDirective, template, viewContainerRef) {
2529
- this.formDirective = formDirective;
2530
- this.template = template;
2531
- this.viewContainerRef = viewContainerRef;
2397
+ buildGroups(builderFormState, form, controls) {
2398
+ for (const [controlId, options] of this.formGroups.entries()) {
2399
+ const formState = this.coerceToGroupFormState(controlId, {}, builderFormState, options.state);
2400
+ assertIsObject(formState);
2401
+ const formGroupDefinition = new RxapFormBuilder(options.definition, this.injector, this.providers).build(formState, {
2402
+ ...options,
2403
+ validators: [],
2404
+ asyncValidators: [],
2405
+ });
2406
+ controls[controlId] = formGroupDefinition.rxapFormGroup;
2407
+ const formGroup = formGroupDefinition.rxapFormGroup;
2408
+ // TODO : add support for injectable validators
2409
+ formGroup.setValidators(this.coerceToValidatorArray(form, options.validators, this.validators.get(controlId)), false);
2410
+ formGroup.setAsyncValidators(this.coerceToValidatorArray(form, options.asyncValidators, this.asyncValidators.get(controlId)), false);
2411
+ // set the form group definition instance to the form definition instance
2412
+ Reflect.set(form, controlId, formGroupDefinition);
2413
+ }
2532
2414
  }
2533
- ngAfterViewInit() {
2534
- this.subscription = this.formDirective.submitError$.pipe(tap(error => {
2535
- this.viewContainerRef.clear();
2536
- if (error !== null) {
2537
- this.viewContainerRef.createEmbeddedView(this.template, { $implicit: error });
2415
+ buildControls(builderFormState, form, controls) {
2416
+ for (const [controlId, options] of this.formControls.entries()) {
2417
+ const control = (controls[controlId] = new (options.controlType ??
2418
+ RxapFormControl)(this.coerceToControlFormState(controlId, null, builderFormState, options.state), {
2419
+ ...options,
2420
+ controlId,
2421
+ validators: [],
2422
+ asyncValidators: [],
2423
+ }));
2424
+ const injectValidators = [];
2425
+ const injectAsyncValidators = [];
2426
+ for (const injectValidator of options.injectValidators ?? []) {
2427
+ const injectableValidator = this.injector.get(injectValidator);
2428
+ if (injectableValidator.validate) {
2429
+ injectValidators.push(injectableValidator.validate.bind(injectableValidator));
2430
+ }
2431
+ if (injectableValidator.asyncValidate) {
2432
+ injectAsyncValidators.push(injectableValidator.asyncValidate.bind(injectableValidator));
2433
+ }
2538
2434
  }
2539
- })).subscribe();
2540
- }
2541
- ngOnDestroy() {
2542
- this.subscription?.unsubscribe();
2435
+ control.setValidators(this.coerceToValidatorArray(form, options.validators, this.validators.get(controlId), injectValidators), false);
2436
+ control.setAsyncValidators(this.coerceToValidatorArray(form, options.asyncValidators, this.asyncValidators.get(controlId), injectAsyncValidators), false);
2437
+ // register all control on change function with the form control
2438
+ this.coerceToFnArray(form, this.controlChanges.get(controlId)).forEach((changeFn) => control.registerOnChange(changeFn));
2439
+ // register all control on set value function with the form control
2440
+ this.coerceToFnArray(form, this.controlSetValue.get(controlId)).forEach((setValueFn) => control.registerOnSetValue(setValueFn));
2441
+ if (Array.isArray(options.validators)) {
2442
+ if (options.validators.includes(Validators.required) ||
2443
+ options.validators.includes(Validators.requiredTrue)) {
2444
+ Reflect.set(control, 'hasRequiredValidator', true);
2445
+ }
2446
+ }
2447
+ // set the form control instance to the form definition instance
2448
+ Reflect.set(form, controlId, control);
2449
+ }
2543
2450
  }
2544
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormSubmitFailedDirective, deps: [{ token: FormDirective }, { token: TemplateRef }, { token: ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive }); }
2545
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: FormSubmitFailedDirective, isStandalone: true, selector: "[rxapFormSubmitFailed]", ngImport: i0 }); }
2546
- }
2547
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormSubmitFailedDirective, decorators: [{
2548
- type: Directive,
2549
- args: [{
2550
- selector: '[rxapFormSubmitFailed]',
2551
- standalone: true,
2552
- }]
2553
- }], ctorParameters: () => [{ type: FormDirective, decorators: [{
2554
- type: Inject,
2555
- args: [FormDirective]
2556
- }] }, { type: i0.TemplateRef, decorators: [{
2557
- type: Inject,
2558
- args: [TemplateRef]
2559
- }] }, { type: i0.ViewContainerRef, decorators: [{
2560
- type: Inject,
2561
- args: [ViewContainerRef]
2562
- }] }] });
2563
-
2564
- class FormSubmitInvalidDirective {
2565
- constructor(formDirective, template, viewContainerRef) {
2566
- this.formDirective = formDirective;
2567
- this.template = template;
2568
- this.viewContainerRef = viewContainerRef;
2451
+ /**
2452
+ * Coerce to a function array.
2453
+ *
2454
+ * @param form the current form definition instance
2455
+ * @param methodKeys A set of propertyKeys that points to form
2456
+ * definition instance methods
2457
+ */
2458
+ coerceToFnArray(form, methodKeys) {
2459
+ const changes = [];
2460
+ if (methodKeys) {
2461
+ for (const propertyKeyOrOptions of methodKeys) {
2462
+ const propertyKey = typeof propertyKeyOrOptions === 'string'
2463
+ ? propertyKeyOrOptions
2464
+ : propertyKeyOrOptions.propertyKey;
2465
+ assertIsFunction(form[propertyKey]);
2466
+ changes.push(form[propertyKey].bind(form));
2467
+ }
2468
+ }
2469
+ return changes;
2569
2470
  }
2570
- ngAfterViewInit() {
2571
- this.subscription = this.formDirective.invalidSubmit.pipe(tap(result => {
2572
- this.viewContainerRef.clear();
2573
- this.viewContainerRef.createEmbeddedView(this.template, { $implicit: result });
2574
- })).subscribe();
2471
+ /**
2472
+ * Coerce to a validator function array.
2473
+ *
2474
+ * @param form the current form definition instance
2475
+ * @param optionsValidators The options validator functions
2476
+ * @param validatorMethodKeys A set of propertyKeys that points to form
2477
+ * definition instance methods
2478
+ * @param injectValidators Injected validator functions
2479
+ */
2480
+ coerceToValidatorArray(form, optionsValidators, validatorMethodKeys, injectValidators) {
2481
+ const validators = (optionsValidators ? Array.isArray(optionsValidators) ? optionsValidators : [optionsValidators] : []).slice();
2482
+ if (validatorMethodKeys) {
2483
+ validatorMethodKeys.forEach((propertyKey) => {
2484
+ assertIsFunction(form[propertyKey]);
2485
+ validators.push(form[propertyKey].bind(form));
2486
+ });
2487
+ }
2488
+ if (injectValidators) {
2489
+ validators.push(...injectValidators);
2490
+ }
2491
+ return validators;
2575
2492
  }
2576
- ngOnDestroy() {
2577
- this.subscription?.unsubscribe();
2493
+ /**
2494
+ * Coerce to the form state for the specified controlId. If none form state is
2495
+ * found the default form state will be returned.
2496
+ *
2497
+ * @param controlId A control id
2498
+ * @param defaultFormState The default form state
2499
+ * @param builderFormState The form state provides as build state parameter
2500
+ * @param optionsFormState The form state set by the decorator in the form definition
2501
+ */
2502
+ coerceToControlFormState(controlId, defaultFormState, builderFormState, optionsFormState) {
2503
+ let formState = defaultFormState;
2504
+ if (builderFormState && builderFormState[controlId] !== undefined) {
2505
+ formState = builderFormState[controlId];
2506
+ }
2507
+ else if (optionsFormState !== undefined) {
2508
+ formState = optionsFormState ?? null;
2509
+ }
2510
+ if (typeof formState === 'function') {
2511
+ formState = formState();
2512
+ }
2513
+ return formState;
2578
2514
  }
2579
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormSubmitInvalidDirective, deps: [{ token: FormDirective }, { token: TemplateRef }, { token: ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive }); }
2580
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: FormSubmitInvalidDirective, isStandalone: true, selector: "[rxapFormSubmitInvalid]", ngImport: i0 }); }
2581
- }
2582
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormSubmitInvalidDirective, decorators: [{
2583
- type: Directive,
2584
- args: [{
2585
- selector: '[rxapFormSubmitInvalid]',
2586
- standalone: true,
2587
- }]
2588
- }], ctorParameters: () => [{ type: FormDirective, decorators: [{
2589
- type: Inject,
2590
- args: [FormDirective]
2591
- }] }, { type: i0.TemplateRef, decorators: [{
2592
- type: Inject,
2593
- args: [TemplateRef]
2594
- }] }, { type: i0.ViewContainerRef, decorators: [{
2595
- type: Inject,
2596
- args: [ViewContainerRef]
2597
- }] }] });
2598
-
2599
- class FormSubmitSuccessfulDirective {
2600
- constructor(formDirective, template, viewContainerRef) {
2601
- this.formDirective = formDirective;
2602
- this.template = template;
2603
- this.viewContainerRef = viewContainerRef;
2515
+ /**
2516
+ * Coerce to the form state for the specified controlId. If none form state is
2517
+ * found the default form state will be returned.
2518
+ *
2519
+ * The difference to the method coerceToControlFormState is that null will be
2520
+ * handled as undefined and the defaultFormState is used
2521
+ *
2522
+ * @param controlId A control id
2523
+ * @param defaultFormState The default form state
2524
+ * @param builderFormState The form state provides as build state parameter
2525
+ * @param optionsFormState The form state set by the decorator in the form definition
2526
+ */
2527
+ coerceToGroupFormState(controlId, defaultFormState, builderFormState, optionsFormState) {
2528
+ let formState = defaultFormState;
2529
+ if (builderFormState && builderFormState[controlId]) {
2530
+ formState = builderFormState[controlId];
2531
+ }
2532
+ else if (optionsFormState) {
2533
+ formState = optionsFormState;
2534
+ }
2535
+ if (typeof formState === 'function') {
2536
+ formState = formState();
2537
+ if (!formState) {
2538
+ throw new Error(`The form state function for the form group '${controlId}' returns a empty value (null/undefined)`);
2539
+ }
2540
+ if (typeof formState !== 'object') {
2541
+ throw new Error(`The form state function for the form group '${controlId}' returns a non object like value instead '${typeof formState}'`);
2542
+ }
2543
+ }
2544
+ return formState;
2604
2545
  }
2605
- ngAfterViewInit() {
2606
- this.subscription = this.formDirective.submitSuccessful$.pipe(tap(result => {
2607
- this.viewContainerRef.clear();
2608
- this.viewContainerRef.createEmbeddedView(this.template, { $implicit: result });
2609
- })).subscribe();
2546
+ /**
2547
+ * Coerce to the form state for the specified controlId. If none form state is
2548
+ * found the default form state will be returned.
2549
+ *
2550
+ * The difference to the method coerceToControlFormState is that null will be
2551
+ * handled as undefined and the defaultFormState is used
2552
+ *
2553
+ * @param controlId A control id
2554
+ * @param defaultFormState The default form state
2555
+ * @param builderFormState The form state provides as build state parameter
2556
+ * @param optionsFormState The form state set by the decorator in the form definition
2557
+ */
2558
+ coerceToArrayFormState(controlId, defaultFormState, builderFormState, optionsFormState) {
2559
+ let formState = defaultFormState;
2560
+ if (builderFormState && builderFormState[controlId] && Array.isArray(builderFormState[controlId])) {
2561
+ formState = builderFormState[controlId];
2562
+ }
2563
+ else if (optionsFormState && Array.isArray(optionsFormState)) {
2564
+ formState = optionsFormState;
2565
+ }
2566
+ if (typeof formState === 'function') {
2567
+ formState = formState();
2568
+ if (!formState) {
2569
+ throw new Error(`The form state function for the form array '${controlId}' returns a empty value (null/undefined)`);
2570
+ }
2571
+ if (!Array.isArray(formState)) {
2572
+ throw new Error(`The form state function for the form array '${controlId}' returns a non array like value instead '${typeof formState}'`);
2573
+ }
2574
+ }
2575
+ return formState;
2610
2576
  }
2611
- ngOnDestroy() {
2612
- this.subscription?.unsubscribe();
2577
+ extractControlChanges() {
2578
+ return (getMetadata(MetadataKeys.CONTROL_CHANGES, this.definition.prototype) ??
2579
+ new Map());
2613
2580
  }
2614
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormSubmitSuccessfulDirective, deps: [{ token: FormDirective }, { token: TemplateRef }, { token: ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive }); }
2615
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: FormSubmitSuccessfulDirective, isStandalone: true, selector: "[rxapFormSubmitSuccessful]", ngImport: i0 }); }
2616
- }
2617
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormSubmitSuccessfulDirective, decorators: [{
2618
- type: Directive,
2619
- args: [{
2620
- selector: '[rxapFormSubmitSuccessful]',
2621
- standalone: true,
2622
- }]
2623
- }], ctorParameters: () => [{ type: FormDirective, decorators: [{
2624
- type: Inject,
2625
- args: [FormDirective]
2626
- }] }, { type: i0.TemplateRef, decorators: [{
2627
- type: Inject,
2628
- args: [TemplateRef]
2629
- }] }, { type: i0.ViewContainerRef, decorators: [{
2630
- type: Inject,
2631
- args: [ViewContainerRef]
2632
- }] }] });
2633
-
2634
- class FormSubmitDirective extends ConfirmClick {
2635
- constructor(formDirective, router = null) {
2636
- super();
2637
- this.formDirective = formDirective;
2638
- this.router = router;
2639
- this.type = input('button', ...(ngDevMode ? [{ debugName: "type" }] : /* istanbul ignore next */ []));
2640
- this.resetAfterSubmit = input(false, { ...(ngDevMode ? { debugName: "resetAfterSubmit" } : /* istanbul ignore next */ {}), transform: coerceBoolean });
2641
- this.navigateAfterSubmit = input(...(ngDevMode ? [undefined, { debugName: "navigateAfterSubmit" }] : /* istanbul ignore next */ []));
2642
- this.afterSubmit = output();
2643
- this.disableWhileSubmitting = input(true, ...(ngDevMode ? [{ debugName: "disableWhileSubmitting" }] : /* istanbul ignore next */ []));
2644
- this.submitting = toSignal(this.formDirective.submitting$, { initialValue: false });
2645
- this.disabled = computed(() => this.disableWhileSubmitting() && this.submitting(), ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
2581
+ extractControlSetValue() {
2582
+ return (getMetadata(MetadataKeys.CONTROL_SET_VALUE, this.definition.prototype) ??
2583
+ new Map());
2646
2584
  }
2647
- execute() {
2648
- this.formDirective.form.markAllAsDirty();
2649
- this.formDirective.form.markAllAsTouched();
2650
- this.formDirective.cdr.markForCheck();
2651
- this.subscription = this.formDirective.rxapSubmit.pipe(take(1), tap(value => {
2652
- const clonedValue = clone(value);
2653
- this.afterSubmit.emit(clonedValue);
2654
- if (this.resetAfterSubmit()) {
2655
- this.formDirective.reset();
2656
- }
2657
- const navigateAfterSubmit = this.navigateAfterSubmit();
2658
- if (Array.isArray(navigateAfterSubmit)) {
2659
- if (!this.router) {
2660
- throw new Error('Could not resolve the router!');
2661
- }
2662
- return this.router.navigate(navigateAfterSubmit);
2663
- }
2664
- return Promise.resolve();
2665
- })).subscribe();
2666
- this.formDirective.onSubmit(new Event('submit'));
2585
+ extractValidators() {
2586
+ return (getMetadata(MetadataKeys.CONTROL_VALIDATORS, this.definition.prototype) ??
2587
+ new Map());
2667
2588
  }
2668
- ngOnDestroy() {
2669
- this.subscription?.unsubscribe();
2589
+ extractAsyncValidators() {
2590
+ return (getMetadata(MetadataKeys.CONTROL_ASYNC_VALIDATORS, this.definition.prototype) ?? new Map());
2670
2591
  }
2671
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormSubmitDirective, deps: [{ token: FormDirective }, { token: Router, optional: true }], target: i0.ɵɵFactoryTarget.Directive }); }
2672
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.9", type: FormSubmitDirective, isStandalone: true, selector: "[rxapFormSubmit]", inputs: { type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: false, transformFunction: null }, resetAfterSubmit: { classPropertyName: "resetAfterSubmit", publicName: "resetAfterSubmit", isSignal: true, isRequired: false, transformFunction: null }, navigateAfterSubmit: { classPropertyName: "navigateAfterSubmit", publicName: "navigateAfterSubmit", isSignal: true, isRequired: false, transformFunction: null }, disableWhileSubmitting: { classPropertyName: "disableWhileSubmitting", publicName: "disableWhileSubmitting", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { afterSubmit: "afterSubmit" }, host: { listeners: { "click": "onClick()", "confirmed": "onConfirm()" }, properties: { "disabled": "disabled()", "type": "type()" } }, exportAs: ["rxapFormSubmit"], usesInheritance: true, ngImport: i0 }); }
2673
- }
2674
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormSubmitDirective, decorators: [{
2675
- type: Directive,
2676
- args: [{
2677
- selector: '[rxapFormSubmit]',
2678
- host: {
2679
- '(click)': 'onClick()',
2680
- '(confirmed)': 'onConfirm()',
2681
- '[disabled]': 'disabled()',
2682
- '[type]': 'type()',
2683
- },
2684
- standalone: true,
2685
- exportAs: 'rxapFormSubmit',
2686
- }]
2687
- }], ctorParameters: () => [{ type: FormDirective, decorators: [{
2688
- type: Inject,
2689
- args: [FormDirective]
2690
- }] }, { type: i2$1.Router, decorators: [{
2691
- type: Optional
2692
- }, {
2693
- type: Inject,
2694
- args: [Router]
2695
- }] }], propDecorators: { type: [{ type: i0.Input, args: [{ isSignal: true, alias: "type", required: false }] }], resetAfterSubmit: [{ type: i0.Input, args: [{ isSignal: true, alias: "resetAfterSubmit", required: false }] }], navigateAfterSubmit: [{ type: i0.Input, args: [{ isSignal: true, alias: "navigateAfterSubmit", required: false }] }], afterSubmit: [{ type: i0.Output, args: ["afterSubmit"] }], disableWhileSubmitting: [{ type: i0.Input, args: [{ isSignal: true, alias: "disableWhileSubmitting", required: false }] }] } });
2696
-
2697
- class FormSubmittingDirective {
2698
- constructor(formDirective, template, viewContainerRef) {
2699
- this.formDirective = formDirective;
2700
- this.template = template;
2701
- this.viewContainerRef = viewContainerRef;
2592
+ extractArrayGroups() {
2593
+ return (getMetadata(MetadataKeys.FORM_ARRAY_GROUPS, this.definition.prototype) ??
2594
+ new Map());
2702
2595
  }
2703
- ngAfterViewInit() {
2704
- this.subscription = this.formDirective.submitting$.pipe(distinctUntilChanged(), tap(loading => {
2705
- this.viewContainerRef.clear();
2706
- if (loading) {
2707
- this.viewContainerRef.createEmbeddedView(this.template);
2708
- }
2709
- })).subscribe();
2596
+ extractArrayControls() {
2597
+ return (getMetadata(MetadataKeys.FORM_ARRAY_CONTROLS, this.definition.prototype) ?? new Map());
2710
2598
  }
2711
- ngOnDestroy() {
2712
- this.subscription?.unsubscribe();
2599
+ extractGroups() {
2600
+ return (getMetadata(MetadataKeys.FORM_GROUPS, this.definition.prototype) ??
2601
+ new Map());
2713
2602
  }
2714
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormSubmittingDirective, deps: [{ token: FormDirective }, { token: TemplateRef }, { token: ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive }); }
2715
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: FormSubmittingDirective, isStandalone: true, selector: "[rxapFormSubmitting]", ngImport: i0 }); }
2716
- }
2717
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormSubmittingDirective, decorators: [{
2718
- type: Directive,
2719
- args: [{
2720
- selector: '[rxapFormSubmitting]',
2721
- standalone: true,
2722
- }]
2723
- }], ctorParameters: () => [{ type: FormDirective, decorators: [{
2724
- type: Inject,
2725
- args: [FormDirective]
2726
- }] }, { type: i0.TemplateRef, decorators: [{
2727
- type: Inject,
2728
- args: [TemplateRef]
2729
- }] }, { type: i0.ViewContainerRef, decorators: [{
2730
- type: Inject,
2731
- args: [ViewContainerRef]
2732
- }] }] });
2733
-
2734
- class ParentControlContainerDirective {
2735
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: ParentControlContainerDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
2736
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: ParentControlContainerDirective, isStandalone: true, selector: "[formControlName][parentControlContainer],[formControlGroup][parentControlContainer]", providers: [
2737
- {
2738
- provide: ControlContainer,
2739
- useExisting: ControlContainer,
2740
- },
2741
- ], ngImport: i0 }); }
2742
- }
2743
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: ParentControlContainerDirective, decorators: [{
2744
- type: Directive,
2745
- args: [{
2746
- // eslint-disable-next-line @angular-eslint/directive-selector
2747
- selector: '[formControlName][parentControlContainer],[formControlGroup][parentControlContainer]',
2748
- providers: [
2749
- {
2750
- provide: ControlContainer,
2751
- useExisting: ControlContainer,
2752
- },
2753
- ],
2754
- standalone: true,
2755
- }]
2756
- }] });
2757
-
2758
- class RxapFormsModule {
2759
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RxapFormsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
2760
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.2.9", ngImport: i0, type: RxapFormsModule, imports: [FormDirective,
2761
- FormSubmitFailedDirective,
2762
- FormLoadingDirective,
2763
- FormSubmittingDirective,
2764
- FormLoadingErrorDirective,
2765
- FormLoadedDirective,
2766
- FormControlErrorDirective,
2767
- FormControlMarkDirtyDirective,
2768
- FormControlMarkTouchedDirective,
2769
- FormControlMarkUntouchedDirective,
2770
- FormControlMarkPristineDirective,
2771
- FormSubmitDirective,
2772
- FormGroupNameDirective,
2773
- FormControlNameDirective,
2774
- ParentControlContainerDirective,
2775
- FormSubmitSuccessfulDirective,
2776
- FormSubmitInvalidDirective], exports: [FormDirective,
2777
- FormSubmitFailedDirective,
2778
- FormLoadingDirective,
2779
- FormSubmittingDirective,
2780
- FormLoadingErrorDirective,
2781
- FormLoadedDirective,
2782
- FormControlErrorDirective,
2783
- FormControlMarkDirtyDirective,
2784
- FormControlMarkTouchedDirective,
2785
- FormControlMarkUntouchedDirective,
2786
- FormControlMarkPristineDirective,
2787
- FormSubmitDirective,
2788
- FormGroupNameDirective,
2789
- FormControlNameDirective,
2790
- ParentControlContainerDirective,
2791
- FormSubmitSuccessfulDirective,
2792
- FormSubmitInvalidDirective] }); }
2793
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RxapFormsModule }); }
2794
- }
2795
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RxapFormsModule, decorators: [{
2796
- type: NgModule,
2797
- args: [{
2798
- imports: [
2799
- FormDirective,
2800
- FormSubmitFailedDirective,
2801
- FormLoadingDirective,
2802
- FormSubmittingDirective,
2803
- FormLoadingErrorDirective,
2804
- FormLoadedDirective,
2805
- FormControlErrorDirective,
2806
- FormControlMarkDirtyDirective,
2807
- FormControlMarkTouchedDirective,
2808
- FormControlMarkUntouchedDirective,
2809
- FormControlMarkPristineDirective,
2810
- FormSubmitDirective,
2811
- FormGroupNameDirective,
2812
- FormControlNameDirective,
2813
- ParentControlContainerDirective,
2814
- FormSubmitSuccessfulDirective,
2815
- FormSubmitInvalidDirective,
2816
- ],
2817
- exports: [
2818
- FormDirective,
2819
- FormSubmitFailedDirective,
2820
- FormLoadingDirective,
2821
- FormSubmittingDirective,
2822
- FormLoadingErrorDirective,
2823
- FormLoadedDirective,
2824
- FormControlErrorDirective,
2825
- FormControlMarkDirtyDirective,
2826
- FormControlMarkTouchedDirective,
2827
- FormControlMarkUntouchedDirective,
2828
- FormControlMarkPristineDirective,
2829
- FormSubmitDirective,
2830
- FormGroupNameDirective,
2831
- FormControlNameDirective,
2832
- ParentControlContainerDirective,
2833
- FormSubmitSuccessfulDirective,
2834
- FormSubmitInvalidDirective,
2835
- ],
2836
- }]
2837
- }] });
2838
-
2839
- function ToFormMethod(call) {
2840
- return { call };
2841
- }
2842
- /**
2843
- * @deprecated use ToFormMethod instead
2844
- *
2845
- * @param call the call method implementation
2846
- */
2847
- function ToFormSubmitMethod(call) {
2848
- return ToFormMethod(call);
2849
- }
2850
-
2851
- function ControlAsyncValidator(...controlIds) {
2852
- return function (target, propertyKey) {
2853
- for (const controlId of controlIds) {
2854
- setMetadataMapSet(controlId, propertyKey, MetadataKeys.CONTROL_ASYNC_VALIDATORS, target);
2855
- }
2856
- };
2857
- }
2858
-
2859
- function ControlChange(...controlIds) {
2860
- return function (target, propertyKey) {
2861
- for (const controlId of controlIds) {
2862
- setMetadataMapSet(controlId, propertyKey, MetadataKeys.CONTROL_CHANGES, target);
2603
+ extractControls() {
2604
+ return (getMetadata(MetadataKeys.FORM_CONTROLS, this.definition.prototype) ??
2605
+ new Map());
2606
+ }
2607
+ extractFormOptions() {
2608
+ const options = GetDefinitionMetadata(this.definition);
2609
+ if (!options || !options['id']) {
2610
+ throw new Error('Ensure that the @UseForm decorator is used.');
2863
2611
  }
2864
- };
2865
- }
2866
-
2867
- function ControlSetValue(controlId, options = {}) {
2868
- return function (target, propertyKey) {
2869
- setMetadataMapSet(controlId, {
2870
- ...options,
2871
- propertyKey,
2872
- }, MetadataKeys.CONTROL_SET_VALUE, target);
2873
- };
2874
- }
2875
-
2876
- function ControlValidator(...controlIds) {
2877
- return function (target, propertyKey) {
2878
- for (const controlId of controlIds) {
2879
- setMetadataMapSet(controlId, propertyKey, MetadataKeys.CONTROL_VALIDATORS, target);
2612
+ if (!options['providers']) {
2613
+ options['providers'] = [];
2880
2614
  }
2881
- };
2882
- }
2883
-
2884
- function RxapForm(optionsOrId, className = 'FormDefinition', packageName = '@rxap/forms') {
2885
- return function (target) {
2886
- DefinitionMetadata(optionsOrId, className, packageName)(target);
2887
- };
2888
- }
2889
-
2890
- function UseFormArrayGroup(definition, options = {}) {
2891
- return function (target, propertyKey) {
2892
- setMetadataMap(propertyKey, {
2893
- ...options,
2894
- definition,
2895
- }, MetadataKeys.FORM_ARRAY_GROUPS, target);
2896
- };
2897
- }
2898
- function UseFormArrayControl(options = {}) {
2899
- return function (target, propertyKey) {
2900
- setMetadataMap(propertyKey, options, MetadataKeys.FORM_ARRAY_CONTROLS, target);
2901
- };
2902
- }
2903
-
2904
- function UseFormControl(options = {}) {
2905
- return function (target, propertyKey) {
2906
- setMetadataMap(propertyKey, options, MetadataKeys.FORM_CONTROLS, target);
2907
- };
2908
- }
2909
-
2910
- function UseFormGroup(definition, options = {}) {
2911
- return function (target, propertyKey) {
2912
- setMetadataMap(propertyKey, {
2913
- ...options,
2914
- definition,
2915
- }, MetadataKeys.FORM_GROUPS, target);
2916
- };
2917
- }
2918
-
2919
- class ControlValueAccessor {
2920
- constructor() {
2921
- // eslint-disable-next-line @typescript-eslint/no-empty-function
2922
- this.onChange = (value) => {
2923
- };
2924
- // eslint-disable-next-line @typescript-eslint/no-empty-function
2925
- this.onTouched = () => {
2926
- };
2927
- // eslint-disable-next-line @typescript-eslint/no-empty-function
2928
- this.setDisabledState = (isDisabled) => {
2929
- };
2930
- }
2931
- registerOnChange(fn) {
2932
- this.onChange = fn;
2933
- }
2934
- registerOnTouched(fn) {
2935
- this.onTouched = fn;
2615
+ return options;
2936
2616
  }
2937
2617
  }
2938
2618
 
@@ -2943,5 +2623,5 @@ class ControlValueAccessor {
2943
2623
  * Generated bundle index. Do not edit.
2944
2624
  */
2945
2625
 
2946
- export { ControlAsyncValidator, ControlChange, ControlSetValue, ControlValidator, ControlValueAccessor, FormArrayControlManager, FormControlErrorDirective, FormControlMarkDirtyDirective, FormControlMarkPristineDirective, FormControlMarkTouchedDirective, FormControlMarkUntouchedDirective, FormControlNameDirective, FormDirective, FormGroupNameDirective, FormLoadedDirective, FormLoadingDirective, FormLoadingErrorDirective, FormResetDirective, FormSubmitDirective, FormSubmitFailedDirective, FormSubmitInvalidDirective, FormSubmitSuccessfulDirective, FormSubmittingDirective, IsArray, IsBoolean, IsComplex, IsDate, IsEmail, IsEnum, IsIP, IsInt, IsNumber, IsObject, IsPhoneNumber, IsPort, IsString, IsUUID, IsUrl, MetadataKeys, ParentControlContainerDirective, RXAP_FORM_CONTEXT, RXAP_FORM_DEFINITION, RXAP_FORM_DEFINITION_BUILDER, RXAP_FORM_INITIAL_STATE, RXAP_FORM_LOAD_FAILED_METHOD, RXAP_FORM_LOAD_METHOD, RXAP_FORM_LOAD_SUCCESSFUL_METHOD, RXAP_FORM_SUBMIT_FAILED_METHOD, RXAP_FORM_SUBMIT_METHOD, RXAP_FORM_SUBMIT_SUCCESSFUL_METHOD, RxapForm, RxapFormArray, RxapFormBuilder, RxapFormControl, RxapFormGroup, RxapFormsModule, RxapValidators, ToFormMethod, ToFormSubmitMethod, UseFormArrayControl, UseFormArrayGroup, UseFormControl, UseFormGroup, _IsNumber, controlDisabled$, controlDisabledWhile, controlEnabled$, controlEnabledWhile, controlErrorChanges$, controlReadonly$, controlStatusChanges$, controlValueChanges$, disableControl, enableControl, hasErrorAndDirty, hasErrorAndTouched, isNumber, markAllDirty, markAllPristine, markAllUntouched, mergeControlValidators, selectControlValue$, validateControlOn };
2626
+ export { ControlAsyncValidator, ControlChange, ControlSetValue, ControlValidator, ControlValueAccessor, FormArrayControlManager, FormControlErrorDirective, FormControlMarkDirtyDirective, FormControlMarkPristineDirective, FormControlMarkTouchedDirective, FormControlMarkUntouchedDirective, FormControlNameDirective, FormDirective, FormGroupNameDirective, FormLoadedDirective, FormLoadingDirective, FormLoadingErrorDirective, FormResetDirective, FormSubmitDirective, FormSubmitFailedDirective, FormSubmitInvalidDirective, FormSubmitSuccessfulDirective, FormSubmittingDirective, IsArray, IsBoolean, IsComplex, IsDate, IsEmail, IsEnum, IsIP, IsInt, IsNumber, IsObject, IsPhoneNumber, IsPort, IsString, IsUUID, IsUrl, MetadataKeys, ParentControlContainerDirective, RXAP_FORM_CONTEXT, RXAP_FORM_DEFINITION, RXAP_FORM_DEFINITION_BUILDER, RXAP_FORM_INITIAL_STATE, RXAP_FORM_LOAD_FAILED_METHOD, RXAP_FORM_LOAD_METHOD, RXAP_FORM_LOAD_SUCCESSFUL_METHOD, RXAP_FORM_SUBMIT_FAILED_METHOD, RXAP_FORM_SUBMIT_METHOD, RXAP_FORM_SUBMIT_SUCCESSFUL_METHOD, RxapForm, RxapFormArray, RxapFormBuilder, RxapFormControl, RxapFormGroup, RxapValidators, ToFormMethod, ToFormSubmitMethod, UseFormArrayControl, UseFormArrayGroup, UseFormControl, UseFormGroup, _IsNumber, controlDisabled$, controlDisabledWhile, controlEnabled$, controlEnabledWhile, controlErrorChanges$, controlReadonly$, controlStatusChanges$, controlValueChanges$, disableControl, enableControl, hasErrorAndDirty, hasErrorAndTouched, isNumber, markAllDirty, markAllPristine, markAllUntouched, mergeControlValidators, selectControlValue$, validateControlOn };
2947
2627
  //# sourceMappingURL=rxap-forms.mjs.map