@rxap/forms 19.2.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.
- package/CHANGELOG.md +36 -0
- package/compodoc/changelog.html +34 -0
- package/compodoc/classes/FormArrayControlManager.html +13 -10
- package/compodoc/classes/RxapFormArray.html +3 -1
- package/compodoc/classes/RxapFormBuilder.html +13 -10
- package/compodoc/classes/RxapFormControl.html +3 -1
- package/compodoc/classes/RxapFormGroup.html +3 -1
- package/compodoc/dependencies.html +13 -13
- package/compodoc/directives/FormControlErrorDirective.html +97 -166
- package/compodoc/directives/FormControlMarkDirtyDirective.html +5 -107
- package/compodoc/directives/FormControlMarkPristineDirective.html +5 -107
- package/compodoc/directives/FormControlMarkTouchedDirective.html +5 -107
- package/compodoc/directives/FormControlMarkUntouchedDirective.html +5 -107
- package/compodoc/directives/FormControlNameDirective.html +12 -124
- package/compodoc/directives/FormDirective.html +1032 -1057
- package/compodoc/directives/FormGroupNameDirective.html +16 -111
- package/compodoc/directives/FormLoadedDirective.html +16 -96
- package/compodoc/directives/FormLoadingDirective.html +16 -96
- package/compodoc/directives/FormLoadingErrorDirective.html +15 -91
- package/compodoc/directives/FormResetDirective.html +47 -101
- package/compodoc/directives/FormSubmitDirective.html +45 -100
- package/compodoc/directives/FormSubmitFailedDirective.html +15 -91
- package/compodoc/directives/FormSubmitInvalidDirective.html +14 -95
- package/compodoc/directives/FormSubmitSuccessfulDirective.html +14 -95
- package/compodoc/directives/FormSubmittingDirective.html +16 -96
- package/compodoc/graph/dependencies.svg +15 -441
- package/compodoc/js/menu-wc.js +0 -77
- package/compodoc/js/menu-wc_es5.js +1 -1
- package/compodoc/js/search/search_index.js +2 -2
- package/compodoc/modules.html +0 -17
- package/compodoc/overview.html +1 -473
- package/compodoc/properties.html +1 -1
- package/docs/documentation.json +13661 -13712
- package/docs/html/assets/hierarchy.js +1 -1
- package/docs/html/assets/navigation.js +1 -1
- package/docs/html/assets/search.js +1 -1
- package/docs/html/classes/ControlValueAccessor.html +5 -5
- package/docs/html/classes/FormArrayControlManager.html +2 -2
- package/docs/html/classes/FormControlErrorDirective.html +3 -12
- package/docs/html/classes/FormControlMarkDirtyDirective.html +2 -2
- package/docs/html/classes/FormControlMarkPristineDirective.html +2 -2
- package/docs/html/classes/FormControlMarkTouchedDirective.html +2 -2
- package/docs/html/classes/FormControlMarkUntouchedDirective.html +2 -2
- package/docs/html/classes/FormControlNameDirective.html +34 -34
- package/docs/html/classes/FormDirective.html +72 -59
- package/docs/html/classes/FormGroupNameDirective.html +29 -29
- package/docs/html/classes/FormLoadedDirective.html +2 -9
- package/docs/html/classes/FormLoadingDirective.html +2 -9
- package/docs/html/classes/FormLoadingErrorDirective.html +2 -9
- package/docs/html/classes/FormResetDirective.html +4 -4
- package/docs/html/classes/FormSubmitDirective.html +4 -4
- package/docs/html/classes/FormSubmitFailedDirective.html +2 -9
- package/docs/html/classes/FormSubmitInvalidDirective.html +2 -9
- package/docs/html/classes/FormSubmitSuccessfulDirective.html +2 -9
- package/docs/html/classes/FormSubmittingDirective.html +2 -9
- package/docs/html/classes/ParentControlContainerDirective.html +2 -2
- package/docs/html/classes/RxapFormArray.html +96 -79
- package/docs/html/classes/RxapFormBuilder.html +2 -2
- package/docs/html/classes/RxapFormControl.html +92 -75
- package/docs/html/classes/RxapFormGroup.html +93 -77
- package/docs/html/enums/MetadataKeys.html +2 -2
- package/docs/html/functions/ControlAsyncValidator.html +1 -1
- package/docs/html/functions/ControlChange.html +1 -1
- package/docs/html/functions/ControlSetValue.html +1 -1
- package/docs/html/functions/ControlValidator.html +1 -1
- package/docs/html/functions/IsArray.html +1 -1
- package/docs/html/functions/IsBoolean.html +1 -1
- package/docs/html/functions/IsComplex.html +1 -1
- package/docs/html/functions/IsDate.html +1 -1
- package/docs/html/functions/IsEmail.html +1 -1
- package/docs/html/functions/IsEnum.html +1 -1
- package/docs/html/functions/IsIP.html +1 -1
- package/docs/html/functions/IsInt.html +1 -1
- package/docs/html/functions/IsNumber-1.html +2 -2
- package/docs/html/functions/IsObject.html +1 -1
- package/docs/html/functions/IsPhoneNumber.html +1 -1
- package/docs/html/functions/IsPort.html +1 -1
- package/docs/html/functions/IsString.html +1 -1
- package/docs/html/functions/IsUUID.html +1 -1
- package/docs/html/functions/IsUrl.html +1 -1
- package/docs/html/functions/RxapForm.html +1 -1
- package/docs/html/functions/ToFormMethod.html +1 -1
- package/docs/html/functions/ToFormSubmitMethod.html +2 -2
- package/docs/html/functions/UseFormArrayControl.html +1 -1
- package/docs/html/functions/UseFormArrayGroup.html +1 -1
- package/docs/html/functions/UseFormControl.html +1 -1
- package/docs/html/functions/UseFormGroup.html +1 -1
- package/docs/html/functions/_IsNumber.html +1 -1
- package/docs/html/functions/controlDisabledWhile.html +1 -1
- package/docs/html/functions/controlDisabled_.html +1 -1
- package/docs/html/functions/controlEnabledWhile.html +1 -1
- package/docs/html/functions/controlEnabled_.html +1 -1
- package/docs/html/functions/controlErrorChanges_.html +1 -1
- package/docs/html/functions/controlReadonly_.html +1 -1
- package/docs/html/functions/controlStatusChanges_.html +1 -1
- package/docs/html/functions/controlValueChanges_.html +1 -1
- package/docs/html/functions/disableControl.html +1 -1
- package/docs/html/functions/enableControl.html +1 -1
- package/docs/html/functions/hasErrorAndDirty.html +1 -1
- package/docs/html/functions/hasErrorAndTouched.html +1 -1
- package/docs/html/functions/isNumber.html +2 -2
- package/docs/html/functions/markAllDirty.html +1 -1
- package/docs/html/functions/markAllPristine.html +1 -1
- package/docs/html/functions/markAllUntouched.html +1 -1
- package/docs/html/functions/mergeControlValidators.html +1 -1
- package/docs/html/functions/selectControlValue_.html +1 -1
- package/docs/html/functions/validateControlOn.html +1 -1
- package/docs/html/hierarchy.html +1 -1
- package/docs/html/index.html +2 -2
- package/docs/html/interfaces/AbstractControl.html +95 -71
- package/docs/html/interfaces/AbstractControlOptions.html +4 -4
- package/docs/html/interfaces/BoxedValue.html +2 -2
- package/docs/html/interfaces/ComplexityOptions.html +2 -2
- package/docs/html/interfaces/ControlOptions.html +3 -3
- package/docs/html/interfaces/ControlSetValueOptions.html +2 -2
- package/docs/html/interfaces/FormArrayOptions.html +4 -4
- package/docs/html/interfaces/FormDefinition.html +6 -6
- package/docs/html/interfaces/FormDefinitionArray.html +43 -36
- package/docs/html/interfaces/FormDefinitionMetadata.html +5 -5
- package/docs/html/interfaces/FormGroupOptions.html +4 -4
- package/docs/html/interfaces/FormLoadFailedMethod.html +2 -2
- package/docs/html/interfaces/FormLoadMethod.html +2 -2
- package/docs/html/interfaces/FormLoadSuccessfulMethod.html +2 -2
- package/docs/html/interfaces/FormOptions.html +4 -4
- package/docs/html/interfaces/FormSubmitFailedMethod.html +2 -2
- package/docs/html/interfaces/FormSubmitMethod.html +2 -2
- package/docs/html/interfaces/FormSubmitSuccessfulMethod.html +2 -2
- package/docs/html/interfaces/InjectableValidator.html +2 -2
- package/docs/html/interfaces/IsNumberOptions.html +3 -3
- package/docs/html/interfaces/NgValidatorsErrors.html +2 -2
- package/docs/html/interfaces/RxapAbstractControlOptionsWithDefinition.html +4 -4
- package/docs/html/interfaces/_RxapAbstractControlOptions.html +4 -4
- package/docs/html/modules.html +1 -1
- package/docs/html/types/AsyncValidator.html +1 -1
- package/docs/html/types/AsyncValidatorFn.html +1 -1
- package/docs/html/types/ChangeFn.html +1 -1
- package/docs/html/types/ControlEventOptions.html +1 -1
- package/docs/html/types/ControlInsertedFn.html +1 -1
- package/docs/html/types/ControlPath.html +1 -1
- package/docs/html/types/ControlRemovedFn.html +1 -1
- package/docs/html/types/ControlState.html +1 -1
- package/docs/html/types/EmitEvent.html +1 -1
- package/docs/html/types/ExtractAbstractControl.html +1 -1
- package/docs/html/types/ExtractStrings.html +1 -1
- package/docs/html/types/FormBuilderFn.html +1 -1
- package/docs/html/types/FormType.html +1 -1
- package/docs/html/types/KeyValueControls.html +1 -1
- package/docs/html/types/OnlySelf.html +1 -1
- package/docs/html/types/OrBoxedValue.html +1 -1
- package/docs/html/types/RxapAbstractControlOptions.html +1 -1
- package/docs/html/types/SetValueFn.html +1 -1
- package/docs/html/types/ValidationErrors.html +1 -1
- package/docs/html/types/Validator.html +1 -1
- package/docs/html/types/ValidatorFn.html +1 -1
- package/docs/html/types/ValidatorOrOpts.html +1 -1
- package/docs/html/variables/RXAP_FORM_CONTEXT.html +1 -1
- package/docs/html/variables/RXAP_FORM_DEFINITION.html +1 -1
- package/docs/html/variables/RXAP_FORM_DEFINITION_BUILDER.html +1 -1
- package/docs/html/variables/RXAP_FORM_INITIAL_STATE.html +1 -1
- package/docs/html/variables/RXAP_FORM_LOAD_FAILED_METHOD.html +1 -1
- package/docs/html/variables/RXAP_FORM_LOAD_METHOD.html +1 -1
- package/docs/html/variables/RXAP_FORM_LOAD_SUCCESSFUL_METHOD.html +1 -1
- package/docs/html/variables/RXAP_FORM_SUBMIT_FAILED_METHOD.html +1 -1
- package/docs/html/variables/RXAP_FORM_SUBMIT_METHOD.html +1 -1
- package/docs/html/variables/RXAP_FORM_SUBMIT_SUCCESSFUL_METHOD.html +1 -1
- package/docs/html/variables/RxapValidators.html +1 -1
- package/docs/markdown/README.md +1 -1
- package/docs/markdown/classes/ControlValueAccessor.md +8 -8
- package/docs/markdown/classes/FormArrayControlManager.md +6 -6
- package/docs/markdown/classes/FormControlErrorDirective.md +8 -68
- package/docs/markdown/classes/FormControlMarkDirtyDirective.md +4 -12
- package/docs/markdown/classes/FormControlMarkPristineDirective.md +4 -12
- package/docs/markdown/classes/FormControlMarkTouchedDirective.md +4 -12
- package/docs/markdown/classes/FormControlMarkUntouchedDirective.md +4 -12
- package/docs/markdown/classes/FormControlNameDirective.md +38 -58
- package/docs/markdown/classes/FormDirective.md +255 -224
- package/docs/markdown/classes/FormGroupNameDirective.md +33 -47
- package/docs/markdown/classes/FormLoadedDirective.md +4 -62
- package/docs/markdown/classes/FormLoadingDirective.md +4 -62
- package/docs/markdown/classes/FormLoadingErrorDirective.md +4 -62
- package/docs/markdown/classes/FormResetDirective.md +15 -35
- package/docs/markdown/classes/FormSubmitDirective.md +33 -57
- package/docs/markdown/classes/FormSubmitFailedDirective.md +4 -62
- package/docs/markdown/classes/FormSubmitInvalidDirective.md +4 -62
- package/docs/markdown/classes/FormSubmitSuccessfulDirective.md +4 -62
- package/docs/markdown/classes/FormSubmittingDirective.md +4 -62
- package/docs/markdown/classes/ParentControlContainerDirective.md +2 -2
- package/docs/markdown/classes/RxapFormArray.md +132 -103
- package/docs/markdown/classes/RxapFormBuilder.md +4 -4
- package/docs/markdown/classes/RxapFormControl.md +127 -103
- package/docs/markdown/classes/RxapFormGroup.md +140 -117
- package/docs/markdown/enumerations/MetadataKeys.md +10 -10
- package/docs/markdown/functions/ControlAsyncValidator.md +2 -2
- package/docs/markdown/functions/ControlChange.md +2 -2
- package/docs/markdown/functions/ControlSetValue.md +2 -2
- package/docs/markdown/functions/ControlValidator.md +2 -2
- package/docs/markdown/functions/IsArray.md +2 -2
- package/docs/markdown/functions/IsBoolean.md +2 -2
- package/docs/markdown/functions/IsComplex.md +2 -2
- package/docs/markdown/functions/IsDate.md +2 -2
- package/docs/markdown/functions/IsEmail.md +2 -2
- package/docs/markdown/functions/IsEnum.md +2 -2
- package/docs/markdown/functions/IsIP.md +2 -2
- package/docs/markdown/functions/IsInt.md +2 -2
- package/docs/markdown/functions/IsNumber-2.md +2 -2
- package/docs/markdown/functions/IsNumber.md +2 -2
- package/docs/markdown/functions/IsObject.md +2 -2
- package/docs/markdown/functions/IsPhoneNumber.md +2 -2
- package/docs/markdown/functions/IsPort.md +2 -2
- package/docs/markdown/functions/IsString.md +2 -2
- package/docs/markdown/functions/IsUUID.md +2 -2
- package/docs/markdown/functions/IsUrl.md +2 -2
- package/docs/markdown/functions/RxapForm.md +2 -2
- package/docs/markdown/functions/ToFormMethod.md +2 -2
- package/docs/markdown/functions/ToFormSubmitMethod.md +2 -2
- package/docs/markdown/functions/UseFormArrayControl.md +2 -2
- package/docs/markdown/functions/UseFormArrayGroup.md +2 -2
- package/docs/markdown/functions/UseFormControl.md +2 -2
- package/docs/markdown/functions/UseFormGroup.md +2 -2
- package/docs/markdown/functions/controlDisabled$.md +2 -2
- package/docs/markdown/functions/controlDisabledWhile.md +2 -2
- package/docs/markdown/functions/controlEnabled$.md +2 -2
- package/docs/markdown/functions/controlEnabledWhile.md +2 -2
- package/docs/markdown/functions/controlErrorChanges$.md +2 -2
- package/docs/markdown/functions/controlReadonly$.md +2 -2
- package/docs/markdown/functions/controlStatusChanges$.md +2 -2
- package/docs/markdown/functions/controlValueChanges$.md +2 -2
- package/docs/markdown/functions/disableControl.md +2 -2
- package/docs/markdown/functions/enableControl.md +2 -2
- package/docs/markdown/functions/hasErrorAndDirty.md +2 -2
- package/docs/markdown/functions/hasErrorAndTouched.md +2 -2
- package/docs/markdown/functions/isNumber-1.md +2 -2
- package/docs/markdown/functions/markAllDirty.md +2 -2
- package/docs/markdown/functions/markAllPristine.md +2 -2
- package/docs/markdown/functions/markAllUntouched.md +2 -2
- package/docs/markdown/functions/mergeControlValidators.md +2 -2
- package/docs/markdown/functions/selectControlValue$.md +2 -2
- package/docs/markdown/functions/validateControlOn.md +2 -2
- package/docs/markdown/globals.md +2 -3
- package/docs/markdown/interfaces/AbstractControl.md +122 -73
- package/docs/markdown/interfaces/AbstractControlOptions.md +6 -6
- package/docs/markdown/interfaces/BoxedValue.md +4 -4
- package/docs/markdown/interfaces/ComplexityOptions.md +12 -12
- package/docs/markdown/interfaces/ControlOptions.md +10 -10
- package/docs/markdown/interfaces/ControlSetValueOptions.md +4 -4
- package/docs/markdown/interfaces/FormArrayOptions.md +16 -16
- package/docs/markdown/interfaces/FormDefinition.md +7 -7
- package/docs/markdown/interfaces/FormDefinitionArray.md +70 -36
- package/docs/markdown/interfaces/FormDefinitionMetadata.md +15 -15
- package/docs/markdown/interfaces/FormGroupOptions.md +13 -13
- package/docs/markdown/interfaces/FormLoadFailedMethod.md +4 -4
- package/docs/markdown/interfaces/FormLoadMethod.md +4 -4
- package/docs/markdown/interfaces/FormLoadSuccessfulMethod.md +4 -4
- package/docs/markdown/interfaces/FormOptions.md +13 -13
- package/docs/markdown/interfaces/FormSubmitFailedMethod.md +4 -4
- package/docs/markdown/interfaces/FormSubmitMethod.md +4 -4
- package/docs/markdown/interfaces/FormSubmitSuccessfulMethod.md +4 -4
- package/docs/markdown/interfaces/InjectableValidator.md +4 -4
- package/docs/markdown/interfaces/IsNumberOptions.md +6 -6
- package/docs/markdown/interfaces/NgValidatorsErrors.md +9 -9
- package/docs/markdown/interfaces/RxapAbstractControlOptions.md +12 -12
- package/docs/markdown/interfaces/RxapAbstractControlOptionsWithDefinition.md +13 -13
- package/docs/markdown/type-aliases/AsyncValidator.md +2 -2
- package/docs/markdown/type-aliases/AsyncValidatorFn.md +2 -2
- package/docs/markdown/type-aliases/ChangeFn.md +2 -2
- package/docs/markdown/type-aliases/ControlEventOptions.md +2 -2
- package/docs/markdown/type-aliases/ControlInsertedFn.md +2 -2
- package/docs/markdown/type-aliases/ControlPath.md +2 -2
- package/docs/markdown/type-aliases/ControlRemovedFn.md +2 -2
- package/docs/markdown/type-aliases/ControlState.md +2 -2
- package/docs/markdown/type-aliases/EmitEvent.md +2 -2
- package/docs/markdown/type-aliases/ExtractAbstractControl.md +2 -2
- package/docs/markdown/type-aliases/ExtractStrings.md +2 -2
- package/docs/markdown/type-aliases/FormBuilderFn.md +2 -2
- package/docs/markdown/type-aliases/FormType.md +2 -2
- package/docs/markdown/type-aliases/KeyValueControls.md +2 -2
- package/docs/markdown/type-aliases/OnlySelf.md +2 -2
- package/docs/markdown/type-aliases/OrBoxedValue.md +2 -2
- package/docs/markdown/type-aliases/RxapAbstractControlOptions.md +2 -2
- package/docs/markdown/type-aliases/SetValueFn.md +2 -2
- package/docs/markdown/type-aliases/ValidationErrors.md +2 -2
- package/docs/markdown/type-aliases/Validator.md +2 -2
- package/docs/markdown/type-aliases/ValidatorFn.md +2 -2
- package/docs/markdown/type-aliases/ValidatorOrOpts.md +2 -2
- package/docs/markdown/variables/RXAP_FORM_CONTEXT.md +2 -2
- package/docs/markdown/variables/RXAP_FORM_DEFINITION.md +2 -2
- package/docs/markdown/variables/RXAP_FORM_DEFINITION_BUILDER.md +2 -2
- package/docs/markdown/variables/RXAP_FORM_INITIAL_STATE.md +2 -2
- package/docs/markdown/variables/RXAP_FORM_LOAD_FAILED_METHOD.md +2 -2
- package/docs/markdown/variables/RXAP_FORM_LOAD_METHOD.md +2 -2
- package/docs/markdown/variables/RXAP_FORM_LOAD_SUCCESSFUL_METHOD.md +2 -2
- package/docs/markdown/variables/RXAP_FORM_SUBMIT_FAILED_METHOD.md +2 -2
- package/docs/markdown/variables/RXAP_FORM_SUBMIT_METHOD.md +2 -2
- package/docs/markdown/variables/RXAP_FORM_SUBMIT_SUCCESSFUL_METHOD.md +2 -2
- package/docs/markdown/variables/RxapValidators.md +2 -2
- package/docs/wiki/Class.ControlValueAccessor.md +7 -7
- package/docs/wiki/Class.FormArrayControlManager.md +5 -5
- package/docs/wiki/Class.FormControlErrorDirective.md +7 -67
- package/docs/wiki/Class.FormControlMarkDirtyDirective.md +3 -11
- package/docs/wiki/Class.FormControlMarkPristineDirective.md +3 -11
- package/docs/wiki/Class.FormControlMarkTouchedDirective.md +3 -11
- package/docs/wiki/Class.FormControlMarkUntouchedDirective.md +3 -11
- package/docs/wiki/Class.FormControlNameDirective.md +37 -57
- package/docs/wiki/Class.FormDirective.md +254 -223
- package/docs/wiki/Class.FormGroupNameDirective.md +32 -46
- package/docs/wiki/Class.FormLoadedDirective.md +3 -61
- package/docs/wiki/Class.FormLoadingDirective.md +3 -61
- package/docs/wiki/Class.FormLoadingErrorDirective.md +3 -61
- package/docs/wiki/Class.FormResetDirective.md +14 -34
- package/docs/wiki/Class.FormSubmitDirective.md +32 -56
- package/docs/wiki/Class.FormSubmitFailedDirective.md +3 -61
- package/docs/wiki/Class.FormSubmitInvalidDirective.md +3 -61
- package/docs/wiki/Class.FormSubmitSuccessfulDirective.md +3 -61
- package/docs/wiki/Class.FormSubmittingDirective.md +3 -61
- package/docs/wiki/Class.ParentControlContainerDirective.md +1 -1
- package/docs/wiki/Class.RxapFormArray.md +131 -102
- package/docs/wiki/Class.RxapFormBuilder.md +3 -3
- package/docs/wiki/Class.RxapFormControl.md +126 -102
- package/docs/wiki/Class.RxapFormGroup.md +139 -116
- package/docs/wiki/Enumeration.MetadataKeys.md +9 -9
- package/docs/wiki/Function.ControlAsyncValidator.md +1 -1
- package/docs/wiki/Function.ControlChange.md +1 -1
- package/docs/wiki/Function.ControlSetValue.md +1 -1
- package/docs/wiki/Function.ControlValidator.md +1 -1
- package/docs/wiki/Function.IsArray.md +1 -1
- package/docs/wiki/Function.IsBoolean.md +1 -1
- package/docs/wiki/Function.IsComplex.md +1 -1
- package/docs/wiki/Function.IsDate.md +1 -1
- package/docs/wiki/Function.IsEmail.md +1 -1
- package/docs/wiki/Function.IsEnum.md +1 -1
- package/docs/wiki/Function.IsIP.md +1 -1
- package/docs/wiki/Function.IsInt.md +1 -1
- package/docs/wiki/Function.IsNumber.md +1 -1
- package/docs/wiki/Function.IsObject.md +1 -1
- package/docs/wiki/Function.IsPhoneNumber.md +1 -1
- package/docs/wiki/Function.IsPort.md +1 -1
- package/docs/wiki/Function.IsString.md +1 -1
- package/docs/wiki/Function.IsUUID.md +1 -1
- package/docs/wiki/Function.IsUrl.md +1 -1
- package/docs/wiki/Function.RxapForm.md +1 -1
- package/docs/wiki/Function.ToFormMethod.md +1 -1
- package/docs/wiki/Function.ToFormSubmitMethod.md +1 -1
- package/docs/wiki/Function.UseFormArrayControl.md +1 -1
- package/docs/wiki/Function.UseFormArrayGroup.md +1 -1
- package/docs/wiki/Function.UseFormControl.md +1 -1
- package/docs/wiki/Function.UseFormGroup.md +1 -1
- package/docs/wiki/Function._IsNumber.md +1 -1
- package/docs/wiki/Function.controlDisabled$.md +1 -1
- package/docs/wiki/Function.controlDisabledWhile.md +1 -1
- package/docs/wiki/Function.controlEnabled$.md +1 -1
- package/docs/wiki/Function.controlEnabledWhile.md +1 -1
- package/docs/wiki/Function.controlErrorChanges$.md +1 -1
- package/docs/wiki/Function.controlReadonly$.md +1 -1
- package/docs/wiki/Function.controlStatusChanges$.md +1 -1
- package/docs/wiki/Function.controlValueChanges$.md +1 -1
- package/docs/wiki/Function.disableControl.md +1 -1
- package/docs/wiki/Function.enableControl.md +1 -1
- package/docs/wiki/Function.hasErrorAndDirty.md +1 -1
- package/docs/wiki/Function.hasErrorAndTouched.md +1 -1
- package/docs/wiki/Function.isNumber.md +1 -1
- package/docs/wiki/Function.markAllDirty.md +1 -1
- package/docs/wiki/Function.markAllPristine.md +1 -1
- package/docs/wiki/Function.markAllUntouched.md +1 -1
- package/docs/wiki/Function.mergeControlValidators.md +1 -1
- package/docs/wiki/Function.selectControlValue$.md +1 -1
- package/docs/wiki/Function.validateControlOn.md +1 -1
- package/docs/wiki/Interface.AbstractControl.md +121 -72
- package/docs/wiki/Interface.AbstractControlOptions.md +5 -5
- package/docs/wiki/Interface.BoxedValue.md +3 -3
- package/docs/wiki/Interface.ComplexityOptions.md +11 -11
- package/docs/wiki/Interface.ControlOptions.md +9 -9
- package/docs/wiki/Interface.ControlSetValueOptions.md +3 -3
- package/docs/wiki/Interface.FormArrayOptions.md +15 -15
- package/docs/wiki/Interface.FormDefinition.md +6 -6
- package/docs/wiki/Interface.FormDefinitionArray.md +69 -35
- package/docs/wiki/Interface.FormDefinitionMetadata.md +14 -14
- package/docs/wiki/Interface.FormGroupOptions.md +12 -12
- package/docs/wiki/Interface.FormLoadFailedMethod.md +3 -3
- package/docs/wiki/Interface.FormLoadMethod.md +3 -3
- package/docs/wiki/Interface.FormLoadSuccessfulMethod.md +3 -3
- package/docs/wiki/Interface.FormOptions.md +12 -12
- package/docs/wiki/Interface.FormSubmitFailedMethod.md +3 -3
- package/docs/wiki/Interface.FormSubmitMethod.md +3 -3
- package/docs/wiki/Interface.FormSubmitSuccessfulMethod.md +3 -3
- package/docs/wiki/Interface.InjectableValidator.md +3 -3
- package/docs/wiki/Interface.IsNumberOptions.md +5 -5
- package/docs/wiki/Interface.NgValidatorsErrors.md +8 -8
- package/docs/wiki/Interface.RxapAbstractControlOptionsWithDefinition.md +12 -12
- package/docs/wiki/Interface._RxapAbstractControlOptions.md +11 -11
- package/docs/wiki/TypeAlias.AsyncValidator.md +1 -1
- package/docs/wiki/TypeAlias.AsyncValidatorFn.md +1 -1
- package/docs/wiki/TypeAlias.ChangeFn.md +1 -1
- package/docs/wiki/TypeAlias.ControlEventOptions.md +1 -1
- package/docs/wiki/TypeAlias.ControlInsertedFn.md +1 -1
- package/docs/wiki/TypeAlias.ControlPath.md +1 -1
- package/docs/wiki/TypeAlias.ControlRemovedFn.md +1 -1
- package/docs/wiki/TypeAlias.ControlState.md +1 -1
- package/docs/wiki/TypeAlias.EmitEvent.md +1 -1
- package/docs/wiki/TypeAlias.ExtractAbstractControl.md +1 -1
- package/docs/wiki/TypeAlias.ExtractStrings.md +1 -1
- package/docs/wiki/TypeAlias.FormBuilderFn.md +1 -1
- package/docs/wiki/TypeAlias.FormType.md +1 -1
- package/docs/wiki/TypeAlias.KeyValueControls.md +1 -1
- package/docs/wiki/TypeAlias.OnlySelf.md +1 -1
- package/docs/wiki/TypeAlias.OrBoxedValue.md +1 -1
- package/docs/wiki/TypeAlias.RxapAbstractControlOptions.md +1 -1
- package/docs/wiki/TypeAlias.SetValueFn.md +1 -1
- package/docs/wiki/TypeAlias.ValidationErrors.md +1 -1
- package/docs/wiki/TypeAlias.Validator.md +1 -1
- package/docs/wiki/TypeAlias.ValidatorFn.md +1 -1
- package/docs/wiki/TypeAlias.ValidatorOrOpts.md +1 -1
- package/docs/wiki/Variable.RXAP_FORM_CONTEXT.md +1 -1
- package/docs/wiki/Variable.RXAP_FORM_DEFINITION.md +1 -1
- package/docs/wiki/Variable.RXAP_FORM_DEFINITION_BUILDER.md +1 -1
- package/docs/wiki/Variable.RXAP_FORM_INITIAL_STATE.md +1 -1
- package/docs/wiki/Variable.RXAP_FORM_LOAD_FAILED_METHOD.md +1 -1
- package/docs/wiki/Variable.RXAP_FORM_LOAD_METHOD.md +1 -1
- package/docs/wiki/Variable.RXAP_FORM_LOAD_SUCCESSFUL_METHOD.md +1 -1
- package/docs/wiki/Variable.RXAP_FORM_SUBMIT_FAILED_METHOD.md +1 -1
- package/docs/wiki/Variable.RXAP_FORM_SUBMIT_METHOD.md +1 -1
- package/docs/wiki/Variable.RXAP_FORM_SUBMIT_SUCCESSFUL_METHOD.md +1 -1
- package/docs/wiki/Variable.RxapValidators.md +1 -1
- package/docs/wiki/_Sidebar.md +0 -1
- package/docs/wiki/globals.md +1 -2
- package/fesm2022/rxap-forms.mjs +1878 -2197
- package/fesm2022/rxap-forms.mjs.map +1 -1
- package/package.json +35 -30
- package/types/rxap-forms.d.ts +969 -0
- package/docs/html/classes/RxapFormsModule.html +0 -2
- package/docs/markdown/classes/RxapFormsModule.md +0 -19
- package/docs/wiki/Class.RxapFormsModule.md +0 -15
- package/index.d.ts +0 -55
- package/lib/control-actions.d.ts +0 -23
- package/lib/control-value-accessor.d.ts +0 -9
- package/lib/decorators/control-async-validator.d.ts +0 -1
- package/lib/decorators/control-change.d.ts +0 -1
- package/lib/decorators/control-set-value.d.ts +0 -5
- package/lib/decorators/control-validator.d.ts +0 -1
- package/lib/decorators/form.d.ts +0 -2
- package/lib/decorators/metadata-keys.d.ts +0 -10
- package/lib/decorators/use-form-array.d.ts +0 -4
- package/lib/decorators/use-form-control.d.ts +0 -2
- package/lib/decorators/use-form-group.d.ts +0 -3
- package/lib/directives/form-control-error.directive.d.ts +0 -22
- package/lib/directives/form-control-mark-dirty.directive.d.ts +0 -9
- package/lib/directives/form-control-mark-pristine.directive.d.ts +0 -9
- package/lib/directives/form-control-mark-touched.directive.d.ts +0 -9
- package/lib/directives/form-control-mark-untouched.directive.d.ts +0 -9
- package/lib/directives/form-control-name.directive.d.ts +0 -16
- package/lib/directives/form-group-name.directive.d.ts +0 -16
- package/lib/directives/form-loaded.directive.d.ts +0 -14
- package/lib/directives/form-loading-error.directive.d.ts +0 -16
- package/lib/directives/form-loading.directive.d.ts +0 -14
- package/lib/directives/form-reset.directive.d.ts +0 -11
- package/lib/directives/form-submit-failed.directive.d.ts +0 -16
- package/lib/directives/form-submit-invalid.directive.d.ts +0 -16
- package/lib/directives/form-submit-successful.directive.d.ts +0 -16
- package/lib/directives/form-submit.directive.d.ts +0 -22
- package/lib/directives/form-submitting.directive.d.ts +0 -14
- package/lib/directives/form.directive.d.ts +0 -62
- package/lib/directives/forms.module.d.ts +0 -23
- package/lib/directives/models.d.ts +0 -29
- package/lib/directives/parent-control-container.directive.d.ts +0 -5
- package/lib/directives/tokens.d.ts +0 -12
- package/lib/form-array.d.ts +0 -76
- package/lib/form-builder.d.ts +0 -96
- package/lib/form-control.d.ts +0 -64
- package/lib/form-group.d.ts +0 -89
- package/lib/model.d.ts +0 -81
- package/lib/tokens.d.ts +0 -3
- package/lib/types.d.ts +0 -100
- package/lib/validators/index.d.ts +0 -32
- package/lib/validators/is-array.d.ts +0 -4
- package/lib/validators/is-boolean.d.ts +0 -4
- package/lib/validators/is-complex.d.ts +0 -17
- package/lib/validators/is-date.d.ts +0 -4
- package/lib/validators/is-email.d.ts +0 -6
- package/lib/validators/is-enum.d.ts +0 -5
- package/lib/validators/is-int.d.ts +0 -6
- package/lib/validators/is-ip.d.ts +0 -5
- package/lib/validators/is-number.d.ts +0 -24
- package/lib/validators/is-object.d.ts +0 -4
- package/lib/validators/is-phone-number.d.ts +0 -7
- package/lib/validators/is-port.d.ts +0 -4
- package/lib/validators/is-string.d.ts +0 -4
- package/lib/validators/is-url.d.ts +0 -6
- package/lib/validators/is-uuid.d.ts +0 -5
package/fesm2022/rxap-forms.mjs
CHANGED
|
@@ -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 {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
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
|
|
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,56 +416,49 @@ const RxapValidators = {
|
|
|
419
416
|
* @deprecated removed use the rxapControlError or rxapControlErrors directive
|
|
420
417
|
*/
|
|
421
418
|
class FormControlErrorDirective {
|
|
422
|
-
constructor(
|
|
423
|
-
this.template =
|
|
424
|
-
this.parent =
|
|
425
|
-
this.viewContainerRef =
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
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: "
|
|
443
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "
|
|
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
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
451
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormControlErrorDirective, decorators: [{
|
|
446
452
|
type: Directive,
|
|
447
453
|
args: [{
|
|
448
454
|
selector: '[rxapFormControlError]',
|
|
449
455
|
standalone: true,
|
|
450
456
|
}]
|
|
451
|
-
}], ctorParameters: () => [{ type: i0.
|
|
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(
|
|
471
|
-
this.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: "
|
|
483
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "
|
|
472
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormControlMarkDirtyDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
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
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
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
|
-
}]
|
|
492
|
-
type: HostListener,
|
|
493
|
-
args: ['click']
|
|
494
|
-
}] } });
|
|
482
|
+
}] });
|
|
495
483
|
|
|
496
484
|
class FormControlMarkPristineDirective {
|
|
497
|
-
constructor(
|
|
498
|
-
this.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: "
|
|
510
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "
|
|
497
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormControlMarkPristineDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
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
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
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
|
-
}]
|
|
519
|
-
type: HostListener,
|
|
520
|
-
args: ['click']
|
|
521
|
-
}] } });
|
|
507
|
+
}] });
|
|
522
508
|
|
|
523
509
|
class FormControlMarkTouchedDirective {
|
|
524
|
-
constructor(
|
|
525
|
-
this.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: "
|
|
531
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "
|
|
516
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormControlMarkTouchedDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
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
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
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
|
-
}]
|
|
540
|
-
type: HostListener,
|
|
541
|
-
args: ['click']
|
|
542
|
-
}] } });
|
|
526
|
+
}] });
|
|
543
527
|
|
|
544
528
|
class FormControlMarkUntouchedDirective {
|
|
545
|
-
constructor(
|
|
546
|
-
this.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: "
|
|
558
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "
|
|
541
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormControlMarkUntouchedDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
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
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
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
|
-
}]
|
|
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,18 +557,22 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.16", ngImpo
|
|
|
575
557
|
* @deprecated use the ParentControlContainerDirective
|
|
576
558
|
*/
|
|
577
559
|
class FormControlNameDirective extends FormControlName {
|
|
578
|
-
constructor(
|
|
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: "
|
|
582
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "
|
|
567
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormControlNameDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
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,
|
|
585
571
|
useExisting: forwardRef(() => FormControlNameDirective),
|
|
586
572
|
},
|
|
587
573
|
], exportAs: ["rxapFormControl"], usesInheritance: true, ngImport: i0 }); }
|
|
588
574
|
}
|
|
589
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
575
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormControlNameDirective, decorators: [{
|
|
590
576
|
type: Directive,
|
|
591
577
|
args: [{
|
|
592
578
|
selector: '[rxapFormControlName]',
|
|
@@ -596,38 +582,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.16", ngImpo
|
|
|
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: () => [
|
|
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,18 +601,21 @@ class FormGroupNameDirective extends FormGroupName {
|
|
|
640
601
|
// TODO : add type check
|
|
641
602
|
return this.formDirective.getFormGroup(this);
|
|
642
603
|
}
|
|
643
|
-
constructor(
|
|
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: "
|
|
647
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "
|
|
610
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormGroupNameDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
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,
|
|
650
614
|
useExisting: forwardRef(() => FormGroupNameDirective),
|
|
651
615
|
},
|
|
652
616
|
], exportAs: ["rxapFormGroup"], usesInheritance: true, ngImport: i0 }); }
|
|
653
617
|
}
|
|
654
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
618
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: FormGroupNameDirective, decorators: [{
|
|
655
619
|
type: Directive,
|
|
656
620
|
args: [{
|
|
657
621
|
selector: '[rxapFormGroupName]',
|
|
@@ -661,31 +625,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.16", ngImpo
|
|
|
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: () => [
|
|
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,2239 +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
|
-
|
|
703
|
-
|
|
704
|
-
|
|
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
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
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
|
-
|
|
815
|
-
|
|
816
|
-
|
|
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
|
-
|
|
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
|
-
|
|
854
|
-
|
|
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
|
-
|
|
857
|
-
|
|
858
|
-
|
|
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
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
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 (
|
|
884
|
-
//
|
|
885
|
-
|
|
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
|
-
|
|
895
|
-
|
|
896
|
-
|
|
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
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
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
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
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
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
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
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
.
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
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
|
-
|
|
983
|
-
}
|
|
984
|
-
hasErrorAndDirty(errorCode, path) {
|
|
985
|
-
return hasErrorAndDirty(this, errorCode, path);
|
|
862
|
+
return false;
|
|
986
863
|
}
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
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.
|
|
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
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
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
|
-
|
|
1027
|
-
|
|
1028
|
-
this.
|
|
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.
|
|
1069
|
-
|
|
940
|
+
else if (typeof this._formDefinition['toJSON'] === 'function') {
|
|
941
|
+
value = this._formDefinition.toJSON();
|
|
1070
942
|
}
|
|
1071
|
-
|
|
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
|
-
|
|
1081
|
-
const
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
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
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
if (
|
|
1144
|
-
|
|
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
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
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
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1003
|
+
submitSuccessful(value) {
|
|
1004
|
+
this.submitSuccessful$.emit(value);
|
|
1005
|
+
const submitSuccessfulMethod = this.currentSubmitSuccessfulMethod();
|
|
1006
|
+
if (submitSuccessfulMethod) {
|
|
1007
|
+
submitSuccessfulMethod.call(value);
|
|
1175
1008
|
}
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
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
|
-
|
|
1229
|
-
super.
|
|
1230
|
-
|
|
1231
|
-
|
|
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
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
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
|
-
|
|
1247
|
-
|
|
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
|
-
|
|
1250
|
-
|
|
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
|
-
|
|
1253
|
-
|
|
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
|
-
|
|
1256
|
-
|
|
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
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
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
|
-
|
|
1268
|
-
|
|
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
|
-
|
|
1271
|
-
|
|
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
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
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
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
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
|
-
|
|
1333
|
+
return Promise.resolve();
|
|
1334
|
+
})).subscribe();
|
|
1335
|
+
this.formDirective.onSubmit(new Event('submit'));
|
|
1290
1336
|
}
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
if (parent) {
|
|
1294
|
-
if (parent.fullControlPath) {
|
|
1295
|
-
return [parent.fullControlPath, this.controlId].join('.');
|
|
1296
|
-
}
|
|
1297
|
-
}
|
|
1298
|
-
return this.controlId;
|
|
1337
|
+
ngOnDestroy() {
|
|
1338
|
+
this.subscription?.unsubscribe();
|
|
1299
1339
|
}
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
this.
|
|
1319
|
-
this.
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
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
|
-
}
|
|
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
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
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);
|
|
1395
1435
|
}
|
|
1396
|
-
}
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
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);
|
|
1401
1443
|
}
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
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);
|
|
1407
1460
|
}
|
|
1408
|
-
}
|
|
1409
|
-
validateOn(observableValidation) {
|
|
1410
|
-
return validateControlOn(this, observableValidation);
|
|
1411
|
-
}
|
|
1412
|
-
getError(errorCode) {
|
|
1413
|
-
return super.getError(errorCode);
|
|
1414
|
-
}
|
|
1415
|
-
hasError(errorCode) {
|
|
1416
|
-
return super.hasError(errorCode);
|
|
1417
|
-
}
|
|
1418
|
-
setErrors(errors, opts = {}) {
|
|
1419
|
-
return super.setErrors(errors, opts);
|
|
1420
|
-
}
|
|
1421
|
-
setError(key, value, opts = {}) {
|
|
1422
|
-
super.setErrors({ [key]: value }, opts);
|
|
1423
|
-
}
|
|
1424
|
-
hasErrorAndTouched(error) {
|
|
1425
|
-
return hasErrorAndTouched(this, error);
|
|
1426
|
-
}
|
|
1427
|
-
hasErrorAndDirty(error) {
|
|
1428
|
-
return hasErrorAndDirty(this, error);
|
|
1429
|
-
}
|
|
1430
|
-
setEnable(enable = true, opts) {
|
|
1431
|
-
enableControl(this, enable, opts);
|
|
1432
|
-
}
|
|
1433
|
-
setDisable(disable = true, opts) {
|
|
1434
|
-
disableControl(this, disable, opts);
|
|
1435
|
-
}
|
|
1436
|
-
registerOnSetValue(setValueFn) {
|
|
1437
|
-
this._onSetValue.push(setValueFn);
|
|
1438
|
-
}
|
|
1461
|
+
};
|
|
1439
1462
|
}
|
|
1440
1463
|
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
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();
|
|
1446
1502
|
}
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
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);
|
|
1455
1526
|
}
|
|
1456
|
-
|
|
1457
|
-
|
|
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
|
-
}
|
|
1527
|
+
else {
|
|
1528
|
+
control.disable(opts);
|
|
1464
1529
|
}
|
|
1465
1530
|
}
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
this.
|
|
1518
|
-
this.buildArrayGroups(state, form, controls);
|
|
1519
|
-
this.buildArrayControls(state, form, controls);
|
|
1520
|
-
const formOptions = {
|
|
1521
|
-
...this.formOptions,
|
|
1522
|
-
controlId: options.controlId ?? (options.id ? options.id : this.formOptions.id),
|
|
1523
|
-
...options,
|
|
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) => {
|
|
1524
1583
|
};
|
|
1525
|
-
form.rxapFormGroup = new RxapFormGroup(controls, formOptions);
|
|
1526
|
-
Reflect.set(form.rxapFormGroup, '_rxapFormDefinition', form);
|
|
1527
|
-
form.rxapMetadata = this.formOptions;
|
|
1528
|
-
if (HasRxapOnInitMethod(form)) {
|
|
1529
|
-
form.rxapOnInit();
|
|
1530
|
-
}
|
|
1531
|
-
for (const control of Object.values(form.rxapFormGroup.controls)) {
|
|
1532
|
-
if (control.controlId) {
|
|
1533
|
-
const controlSetValueOnInit = Array.from(this.controlSetValue.get(control.controlId) ?? []).filter((controlSetValueOptions) => controlSetValueOptions.initial);
|
|
1534
|
-
for (const onSetValue of this.coerceToFnArray(form, controlSetValueOnInit)) {
|
|
1535
|
-
onSetValue(control.value, { initial: true });
|
|
1536
|
-
}
|
|
1537
|
-
}
|
|
1538
|
-
}
|
|
1539
|
-
return form;
|
|
1540
1584
|
}
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
const formState = this.coerceToArrayFormState(controlId, [], builderFormState, options.state);
|
|
1544
|
-
assertIsArray(formState);
|
|
1545
|
-
const formControls = formState.map((fs, index) => new RxapFormControl(fs, { controlId: index.toFixed(0) }));
|
|
1546
|
-
const manager = new FormArrayControlManager(form, controlId);
|
|
1547
|
-
const formArray = (formControls.rxapFormArray =
|
|
1548
|
-
controls[controlId] =
|
|
1549
|
-
new RxapFormArray(
|
|
1550
|
-
// TODO : add the formControlOptions property. To definition the form control options
|
|
1551
|
-
formControls, {
|
|
1552
|
-
...options,
|
|
1553
|
-
controlId,
|
|
1554
|
-
validators: [],
|
|
1555
|
-
asyncValidators: [],
|
|
1556
|
-
controlInsertedFn: manager.inserted.bind(manager),
|
|
1557
|
-
controlRemovedFn: manager.removed.bind(manager),
|
|
1558
|
-
builder: (state, controlOptions) => new RxapFormControl(state, controlOptions),
|
|
1559
|
-
}));
|
|
1560
|
-
// TODO : add support for injectable validators
|
|
1561
|
-
formArray.setValidators(this.coerceToValidatorArray(form, options.validators, this.validators.get(controlId)), false);
|
|
1562
|
-
formArray.setAsyncValidators(this.coerceToValidatorArray(form, options.asyncValidators, this.asyncValidators.get(controlId)), false);
|
|
1563
|
-
Reflect.set(form, controlId, formControls);
|
|
1564
|
-
}
|
|
1585
|
+
registerOnChange(fn) {
|
|
1586
|
+
this.onChange = fn;
|
|
1565
1587
|
}
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
const formState = this.coerceToArrayFormState(controlId, [], builderFormState, options.state);
|
|
1569
|
-
assertIsArray(formState);
|
|
1570
|
-
const formGroupBuilder = new RxapFormBuilder(options.definition, this.injector, this.providers);
|
|
1571
|
-
// TODO : add the formGroupOptions property. To definition of the form group options
|
|
1572
|
-
const formGroupDefinitions = formState.map((fs, index) => formGroupBuilder.build(fs, { id: index.toFixed(0) }));
|
|
1573
|
-
const manager = new FormArrayControlManager(form, controlId);
|
|
1574
|
-
const formArray = (formGroupDefinitions.rxapFormArray =
|
|
1575
|
-
controls[controlId] =
|
|
1576
|
-
new RxapFormArray(formGroupDefinitions.map((fgd) => fgd.rxapFormGroup), {
|
|
1577
|
-
...options,
|
|
1578
|
-
builder: formGroupBuilder.build.bind(formGroupBuilder),
|
|
1579
|
-
controlId,
|
|
1580
|
-
validators: [],
|
|
1581
|
-
asyncValidators: [],
|
|
1582
|
-
controlInsertedFn: manager.inserted.bind(manager),
|
|
1583
|
-
controlRemovedFn: manager.removed.bind(manager),
|
|
1584
|
-
}));
|
|
1585
|
-
// TODO : add support for injectable validators
|
|
1586
|
-
formArray.setValidators(this.coerceToValidatorArray(form, options.validators, this.validators.get(controlId)), false);
|
|
1587
|
-
formArray.setAsyncValidators(this.coerceToValidatorArray(form, options.asyncValidators, this.asyncValidators.get(controlId)), false);
|
|
1588
|
-
Reflect.set(form, controlId, formGroupDefinitions);
|
|
1589
|
-
}
|
|
1588
|
+
registerOnTouched(fn) {
|
|
1589
|
+
this.onTouched = fn;
|
|
1590
1590
|
}
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
...options,
|
|
1597
|
-
validators: [],
|
|
1598
|
-
asyncValidators: [],
|
|
1599
|
-
});
|
|
1600
|
-
controls[controlId] = formGroupDefinition.rxapFormGroup;
|
|
1601
|
-
const formGroup = formGroupDefinition.rxapFormGroup;
|
|
1602
|
-
// TODO : add support for injectable validators
|
|
1603
|
-
formGroup.setValidators(this.coerceToValidatorArray(form, options.validators, this.validators.get(controlId)), false);
|
|
1604
|
-
formGroup.setAsyncValidators(this.coerceToValidatorArray(form, options.asyncValidators, this.asyncValidators.get(controlId)), false);
|
|
1605
|
-
// set the form group definition instance to the form definition instance
|
|
1606
|
-
Reflect.set(form, controlId, formGroupDefinition);
|
|
1607
|
-
}
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
class RxapFormArray extends UntypedFormArray {
|
|
1594
|
+
get readonly() {
|
|
1595
|
+
return this.parent?.readonly ?? this._readonly;
|
|
1608
1596
|
}
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
if (injectableValidator.asyncValidate) {
|
|
1626
|
-
injectAsyncValidators.push(injectableValidator.asyncValidate.bind(injectableValidator));
|
|
1597
|
+
set readonly(value) {
|
|
1598
|
+
this._readonly = value;
|
|
1599
|
+
this.controls.forEach(control => control.stateChanges?.next());
|
|
1600
|
+
}
|
|
1601
|
+
/**
|
|
1602
|
+
* @internal
|
|
1603
|
+
*/
|
|
1604
|
+
get rxapFormDefinition() {
|
|
1605
|
+
return this.parent.rxapFormDefinition;
|
|
1606
|
+
}
|
|
1607
|
+
get controlPath() {
|
|
1608
|
+
const parent = this.parent;
|
|
1609
|
+
if (parent) {
|
|
1610
|
+
if (parent.controlPath) {
|
|
1611
|
+
if (parent === this.root) {
|
|
1612
|
+
return this.controlId;
|
|
1627
1613
|
}
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
control.setAsyncValidators(this.coerceToValidatorArray(form, options.asyncValidators, this.asyncValidators.get(controlId), injectAsyncValidators), false);
|
|
1631
|
-
// register all control on change function with the form control
|
|
1632
|
-
this.coerceToFnArray(form, this.controlChanges.get(controlId)).forEach((changeFn) => control.registerOnChange(changeFn));
|
|
1633
|
-
// register all control on set value function with the form control
|
|
1634
|
-
this.coerceToFnArray(form, this.controlSetValue.get(controlId)).forEach((setValueFn) => control.registerOnSetValue(setValueFn));
|
|
1635
|
-
if (Array.isArray(options.validators)) {
|
|
1636
|
-
if (options.validators.includes(Validators.required) ||
|
|
1637
|
-
options.validators.includes(Validators.requiredTrue)) {
|
|
1638
|
-
Reflect.set(control, 'hasRequiredValidator', true);
|
|
1614
|
+
else {
|
|
1615
|
+
return [parent.controlPath, this.controlId].join('.');
|
|
1639
1616
|
}
|
|
1640
1617
|
}
|
|
1641
|
-
// set the form control instance to the form definition instance
|
|
1642
|
-
Reflect.set(form, controlId, control);
|
|
1643
1618
|
}
|
|
1619
|
+
return this.controlId;
|
|
1644
1620
|
}
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
* definition instance methods
|
|
1651
|
-
*/
|
|
1652
|
-
coerceToFnArray(form, methodKeys) {
|
|
1653
|
-
const changes = [];
|
|
1654
|
-
if (methodKeys) {
|
|
1655
|
-
for (const propertyKeyOrOptions of methodKeys) {
|
|
1656
|
-
const propertyKey = typeof propertyKeyOrOptions === 'string'
|
|
1657
|
-
? propertyKeyOrOptions
|
|
1658
|
-
: propertyKeyOrOptions.propertyKey;
|
|
1659
|
-
assertIsFunction(form[propertyKey]);
|
|
1660
|
-
changes.push(form[propertyKey].bind(form));
|
|
1621
|
+
get fullControlPath() {
|
|
1622
|
+
const parent = this.parent;
|
|
1623
|
+
if (parent) {
|
|
1624
|
+
if (parent.fullControlPath) {
|
|
1625
|
+
return [parent.fullControlPath, this.controlId].join('.');
|
|
1661
1626
|
}
|
|
1662
1627
|
}
|
|
1663
|
-
return
|
|
1628
|
+
return this.controlId;
|
|
1664
1629
|
}
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
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;
|
|
1686
1651
|
}
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
formState = builderFormState[controlId];
|
|
1700
|
-
}
|
|
1701
|
-
else if (optionsFormState !== undefined) {
|
|
1702
|
-
formState = optionsFormState ?? null;
|
|
1703
|
-
}
|
|
1704
|
-
if (typeof formState === 'function') {
|
|
1705
|
-
formState = formState();
|
|
1652
|
+
select(mapFn) {
|
|
1653
|
+
return this.value$.pipe(map(mapFn), distinctUntilChanged());
|
|
1654
|
+
}
|
|
1655
|
+
at(index) {
|
|
1656
|
+
return super.at(index);
|
|
1657
|
+
}
|
|
1658
|
+
getRawValue() {
|
|
1659
|
+
return super.getRawValue();
|
|
1660
|
+
}
|
|
1661
|
+
insert(index, control) {
|
|
1662
|
+
if (isDevMode()) {
|
|
1663
|
+
console.warn('It is not recommend to use the FormArray.insert method');
|
|
1706
1664
|
}
|
|
1707
|
-
return
|
|
1665
|
+
return super.insert(index, control);
|
|
1708
1666
|
}
|
|
1709
1667
|
/**
|
|
1710
|
-
*
|
|
1711
|
-
*
|
|
1712
|
-
*
|
|
1713
|
-
* The difference to the method coerceToControlFormState is that null will be
|
|
1714
|
-
* handled as undefined and the defaultFormState is used
|
|
1668
|
+
* inserts a new control at the specified index. If the index is undefined
|
|
1669
|
+
* the new control will be added to the end.
|
|
1715
1670
|
*
|
|
1716
|
-
* @param
|
|
1717
|
-
* @param
|
|
1718
|
-
* @param
|
|
1719
|
-
* @param optionsFormState The form state set by the decorator in the form definition
|
|
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
|
|
1720
1674
|
*/
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
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),
|
|
1680
|
+
});
|
|
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
|
+
}
|
|
1725
1687
|
}
|
|
1726
|
-
|
|
1727
|
-
|
|
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);
|
|
1694
|
+
}
|
|
1695
|
+
else {
|
|
1696
|
+
super.insert(insertIndex, controlOrDefinition.rxapFormGroup, options);
|
|
1697
|
+
}
|
|
1728
1698
|
}
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1699
|
+
else {
|
|
1700
|
+
if (controlOrDefinition instanceof AbstractControl) {
|
|
1701
|
+
controlOrDefinition.setParent(this);
|
|
1702
|
+
controlOrDefinition['_registerOnCollectionChange']?.(this['_onCollectionChange']);
|
|
1733
1703
|
}
|
|
1734
|
-
|
|
1735
|
-
|
|
1704
|
+
else {
|
|
1705
|
+
controlOrDefinition.rxapFormGroup.setParent(this);
|
|
1706
|
+
controlOrDefinition.rxapFormGroup['_registerOnCollectionChange']?.(this['_onCollectionChange']);
|
|
1736
1707
|
}
|
|
1708
|
+
this.updateValueAndValidity({ emitEvent: options?.emitEvent });
|
|
1737
1709
|
}
|
|
1738
|
-
return formState;
|
|
1739
1710
|
}
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1711
|
+
disabledWhile(observable, options) {
|
|
1712
|
+
return controlDisabledWhile(this, observable, options);
|
|
1713
|
+
}
|
|
1714
|
+
enabledWhile(observable, options) {
|
|
1715
|
+
return controlEnabledWhile(this, observable, options);
|
|
1716
|
+
}
|
|
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);
|
|
1737
|
+
});
|
|
1756
1738
|
}
|
|
1757
|
-
|
|
1758
|
-
|
|
1739
|
+
super.setValue(valueOrObservable, options);
|
|
1740
|
+
}
|
|
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
1759
|
}
|
|
1760
|
-
if (
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
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);
|
|
1764
|
+
}
|
|
1764
1765
|
}
|
|
1765
|
-
|
|
1766
|
-
|
|
1766
|
+
}
|
|
1767
|
+
value.forEach((newValue, index) => {
|
|
1768
|
+
if (this.at(index)) {
|
|
1769
|
+
this.at(index)
|
|
1770
|
+
.patchValue(newValue, {
|
|
1771
|
+
...(options ?? {}),
|
|
1772
|
+
onlySelf: true,
|
|
1773
|
+
});
|
|
1767
1774
|
}
|
|
1775
|
+
else if (options?.coerce) {
|
|
1776
|
+
this.insertAt(index, value[index]);
|
|
1777
|
+
}
|
|
1778
|
+
});
|
|
1779
|
+
this.updateValueAndValidity(options);
|
|
1780
|
+
}
|
|
1781
|
+
patchValue(valueOrObservable, options) {
|
|
1782
|
+
if (isObservable(valueOrObservable)) {
|
|
1783
|
+
return valueOrObservable.subscribe((value) => {
|
|
1784
|
+
this._patchValue(value, options);
|
|
1785
|
+
});
|
|
1768
1786
|
}
|
|
1769
|
-
|
|
1787
|
+
this._patchValue(valueOrObservable, options);
|
|
1770
1788
|
}
|
|
1771
|
-
|
|
1772
|
-
return (
|
|
1773
|
-
new Map());
|
|
1789
|
+
hasErrorAndDirty(errorCode, path) {
|
|
1790
|
+
return hasErrorAndDirty(this, errorCode, path);
|
|
1774
1791
|
}
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1792
|
+
removeAt(index, opts) {
|
|
1793
|
+
if (isDevMode()) {
|
|
1794
|
+
console.warn('It is not recommend to use the FormArray.removeAt method');
|
|
1795
|
+
}
|
|
1796
|
+
const length = this.controls.length;
|
|
1797
|
+
this._controlRemovedFn(index);
|
|
1798
|
+
if (length === this.controls.length) {
|
|
1799
|
+
super.removeAt(index);
|
|
1800
|
+
}
|
|
1801
|
+
else {
|
|
1802
|
+
this.updateValueAndValidity({ emitEvent: opts?.emitEvent });
|
|
1803
|
+
}
|
|
1778
1804
|
}
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
new Map());
|
|
1805
|
+
setEnable(enable = true, opts) {
|
|
1806
|
+
enableControl(this, enable, opts);
|
|
1782
1807
|
}
|
|
1783
|
-
|
|
1784
|
-
|
|
1808
|
+
push(control, options) {
|
|
1809
|
+
if (isDevMode()) {
|
|
1810
|
+
console.warn('It is not recommend to use the FormArray.push method');
|
|
1811
|
+
}
|
|
1812
|
+
return super.push(control, options);
|
|
1785
1813
|
}
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
new Map());
|
|
1814
|
+
setDisable(disable = true, opts) {
|
|
1815
|
+
disableControl(this, disable, opts);
|
|
1789
1816
|
}
|
|
1790
|
-
|
|
1791
|
-
|
|
1817
|
+
setControl(index, control, options) {
|
|
1818
|
+
if (isDevMode()) {
|
|
1819
|
+
console.warn('It is not recommend to use the FormArray.setControl method');
|
|
1820
|
+
}
|
|
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();
|
|
1846
|
+
}
|
|
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 {
|
|
1866
|
+
/**
|
|
1867
|
+
* @internal
|
|
1868
|
+
*/
|
|
1869
|
+
get rxapFormDefinition() {
|
|
1870
|
+
if (!this.parent) {
|
|
1871
|
+
return this._rxapFormDefinition;
|
|
1872
|
+
}
|
|
1873
|
+
if (this._rxapFormDefinition) {
|
|
1874
|
+
return this._rxapFormDefinition;
|
|
1875
|
+
}
|
|
1876
|
+
return this.parent.rxapFormDefinition;
|
|
1792
1877
|
}
|
|
1793
|
-
|
|
1794
|
-
return
|
|
1795
|
-
new Map());
|
|
1878
|
+
get readonly() {
|
|
1879
|
+
return this.parent?.readonly ?? this._readonly;
|
|
1796
1880
|
}
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1881
|
+
set readonly(value) {
|
|
1882
|
+
this._readonly = value;
|
|
1883
|
+
Object.values(this.controls ?? {}).forEach(control => control.stateChanges?.next());
|
|
1800
1884
|
}
|
|
1801
|
-
|
|
1802
|
-
const
|
|
1803
|
-
if (
|
|
1804
|
-
|
|
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
|
+
}
|
|
1895
|
+
}
|
|
1805
1896
|
}
|
|
1806
|
-
|
|
1807
|
-
|
|
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('.');
|
|
1904
|
+
}
|
|
1808
1905
|
}
|
|
1809
|
-
return
|
|
1906
|
+
return this.controlId;
|
|
1810
1907
|
}
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
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;
|
|
1816
1922
|
}
|
|
1817
|
-
|
|
1818
|
-
return this
|
|
1923
|
+
select(mapFn) {
|
|
1924
|
+
return selectControlValue$(this, mapFn);
|
|
1819
1925
|
}
|
|
1820
|
-
|
|
1821
|
-
return
|
|
1926
|
+
getRawValue() {
|
|
1927
|
+
return super.getRawValue();
|
|
1822
1928
|
}
|
|
1823
|
-
get
|
|
1824
|
-
return
|
|
1929
|
+
get(path) {
|
|
1930
|
+
return super.get(path);
|
|
1825
1931
|
}
|
|
1826
|
-
|
|
1827
|
-
return this.
|
|
1932
|
+
getControl(...names) {
|
|
1933
|
+
return this.get(names.join('.'));
|
|
1828
1934
|
}
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
this._formDefinition = value;
|
|
1832
|
-
this.form = value.rxapFormGroup;
|
|
1833
|
-
}
|
|
1935
|
+
addControl(name, control) {
|
|
1936
|
+
super.addControl(name, control);
|
|
1834
1937
|
}
|
|
1835
|
-
|
|
1836
|
-
|
|
1938
|
+
removeControl(name) {
|
|
1939
|
+
super.removeControl(name);
|
|
1837
1940
|
}
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
submitMethod = null,
|
|
1841
|
-
// skip self, bc the token is set to null
|
|
1842
|
-
loadMethod = null,
|
|
1843
|
-
// skip self, bc the token is set to null
|
|
1844
|
-
loadFailedMethod = null,
|
|
1845
|
-
// skip self, bc the token is set to null
|
|
1846
|
-
loadSuccessfulMethod = null,
|
|
1847
|
-
// skip self, bc the token is set to null
|
|
1848
|
-
submitFailedMethod = null,
|
|
1849
|
-
// skip self, bc the token is set to null
|
|
1850
|
-
submitSuccessfulMethod = null,
|
|
1851
|
-
// skip self, bc the token is set to null
|
|
1852
|
-
formDefinitionBuilder = null, loadingIndicatorService = null, context = null, initial = null) {
|
|
1853
|
-
super([], []);
|
|
1854
|
-
this.cdr = cdr;
|
|
1855
|
-
this.formDefinitionBuilder = formDefinitionBuilder;
|
|
1856
|
-
this.loadingIndicatorService = loadingIndicatorService;
|
|
1857
|
-
this.initial = model(null);
|
|
1858
|
-
this.context = model(null);
|
|
1859
|
-
/**
|
|
1860
|
-
* Emits when the submit method is executed without errors. The result of the
|
|
1861
|
-
* submit method is passed as event object.
|
|
1862
|
-
*
|
|
1863
|
-
* If no submit method is defined then emit after the submit button
|
|
1864
|
-
* is clicked.
|
|
1865
|
-
*/
|
|
1866
|
-
this.rxapSubmit = new EventEmitter();
|
|
1867
|
-
this.invalidSubmit = new EventEmitter();
|
|
1868
|
-
// eslint-disable-next-line @angular-eslint/no-output-rename
|
|
1869
|
-
this.submitSuccessful$ = new EventEmitter();
|
|
1870
|
-
this.submitting$ = new ToggleSubject();
|
|
1871
|
-
this.submitError$ = new BehaviorSubject(null);
|
|
1872
|
-
this.loading$ = new ToggleSubject();
|
|
1873
|
-
this.loaded$ = new ToggleSubject();
|
|
1874
|
-
this.loadingError$ = new BehaviorSubject(null);
|
|
1875
|
-
this.submitMethod = null;
|
|
1876
|
-
this.loadMethod = null;
|
|
1877
|
-
this.loadFailedMethod = null;
|
|
1878
|
-
this.loadSuccessfulMethod = null;
|
|
1879
|
-
this.submitFailedMethod = null;
|
|
1880
|
-
this.submitSuccessfulMethod = null;
|
|
1881
|
-
this._autoSubmitSubscription = new Subscription();
|
|
1882
|
-
this.submitMethod = submitMethod ?? this.submitMethod;
|
|
1883
|
-
this.loadMethod = loadMethod ?? this.loadMethod;
|
|
1884
|
-
this.loadFailedMethod = loadFailedMethod ?? this.loadFailedMethod;
|
|
1885
|
-
this.loadSuccessfulMethod = loadSuccessfulMethod ?? this.loadSuccessfulMethod;
|
|
1886
|
-
this.submitFailedMethod = submitFailedMethod ?? this.submitFailedMethod;
|
|
1887
|
-
this.submitSuccessfulMethod = submitSuccessfulMethod ?? this.submitSuccessfulMethod;
|
|
1888
|
-
if (!formDefinition && formDefinitionBuilder) {
|
|
1889
|
-
formDefinition = formDefinitionBuilder.build();
|
|
1890
|
-
}
|
|
1891
|
-
if (formDefinition) {
|
|
1892
|
-
this._formDefinition = formDefinition;
|
|
1893
|
-
this.form = formDefinition.rxapFormGroup;
|
|
1894
|
-
}
|
|
1895
|
-
this.loadingIndicatorService?.attachLoading(this.loading$);
|
|
1896
|
-
this.loadingIndicatorService?.attachLoading(this.submitting$);
|
|
1897
|
-
if (context) {
|
|
1898
|
-
this.context.set(context);
|
|
1899
|
-
}
|
|
1900
|
-
if (initial && typeof initial === 'object' && !Array.isArray(initial)) {
|
|
1901
|
-
this.initial.set(initial);
|
|
1902
|
-
}
|
|
1941
|
+
contains(controlName) {
|
|
1942
|
+
return super.contains(controlName);
|
|
1903
1943
|
}
|
|
1904
|
-
|
|
1905
|
-
super.
|
|
1906
|
-
const formChange = changes['form'];
|
|
1907
|
-
if (formChange && !formChange.firstChange) {
|
|
1908
|
-
this.loadInitialState(formChange.currentValue);
|
|
1909
|
-
}
|
|
1944
|
+
setControl(name, control) {
|
|
1945
|
+
super.setControl(name, control);
|
|
1910
1946
|
}
|
|
1911
|
-
|
|
1912
|
-
if (
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
if (!this.form) {
|
|
1917
|
-
// TODO : replace with rxap error
|
|
1918
|
-
throw new Error('The form instance is not defined');
|
|
1919
|
-
}
|
|
1920
|
-
this.loadInitialState(this.form);
|
|
1921
|
-
function HasNgOnInitMethod(obj) {
|
|
1922
|
-
return obj && typeof obj.ngOnInit === 'function';
|
|
1923
|
-
}
|
|
1924
|
-
if (HasNgOnInitMethod(this._formDefinition)) {
|
|
1925
|
-
this._formDefinition.ngOnInit();
|
|
1926
|
-
}
|
|
1927
|
-
if (this._formDefinition.rxapMetadata.autoSubmit) {
|
|
1928
|
-
const debounce = typeof this._formDefinition.rxapMetadata.autoSubmit === 'number'
|
|
1929
|
-
? this._formDefinition.rxapMetadata.autoSubmit
|
|
1930
|
-
: 5000;
|
|
1931
|
-
this._autoSubmitSubscription = this
|
|
1932
|
-
.form
|
|
1933
|
-
.valueChanges
|
|
1934
|
-
.pipe(debounceTime(debounce), filter(() => this.form.valid), tap((value) => {
|
|
1935
|
-
if (isDevMode()) {
|
|
1936
|
-
console.debug(`Auto submit form '${this._formDefinition.rxapMetadata.id}'`, value);
|
|
1937
|
-
}
|
|
1938
|
-
}), tap(() => this.submit()))
|
|
1939
|
-
.subscribe();
|
|
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));
|
|
1940
1952
|
}
|
|
1953
|
+
super.setValue(valueOrObservable, options);
|
|
1941
1954
|
}
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
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;
|
|
1947
1962
|
}
|
|
1948
|
-
|
|
1949
|
-
//
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
errorList.push(reduceErrors(item));
|
|
1957
|
-
}
|
|
1958
|
-
errors[control.controlId] = errorList;
|
|
1959
|
-
}
|
|
1960
|
-
else {
|
|
1961
|
-
const innerErrors = {};
|
|
1962
|
-
for (const child of Object.values(control.controls)) {
|
|
1963
|
-
reduceErrors(child, innerErrors);
|
|
1964
|
-
}
|
|
1965
|
-
errors[control.controlId] = innerErrors;
|
|
1966
|
-
}
|
|
1967
|
-
}
|
|
1968
|
-
else {
|
|
1969
|
-
if (control.errors) {
|
|
1970
|
-
errors[control.controlId] = control.errors;
|
|
1971
|
-
}
|
|
1972
|
-
}
|
|
1973
|
-
}
|
|
1974
|
-
return errors;
|
|
1975
|
-
}
|
|
1976
|
-
if (isDevMode()) {
|
|
1977
|
-
console.log('Form submit is not valid for: ' + this.form.controlId, this.form.errors);
|
|
1978
|
-
// eslint-disable-next-line no-inner-declarations
|
|
1979
|
-
function printErrorControls(control) {
|
|
1980
|
-
if (!control.valid) {
|
|
1981
|
-
console.group(control.controlId);
|
|
1982
|
-
if (control.controls) {
|
|
1983
|
-
if (Array.isArray(control.controls)) {
|
|
1984
|
-
for (let i = 0; i < control.controls.length; i++) {
|
|
1985
|
-
const child = control.controls[i];
|
|
1986
|
-
if (!child.valid) {
|
|
1987
|
-
console.group(`index: ${i}`);
|
|
1988
|
-
printErrorControls(child);
|
|
1989
|
-
console.groupEnd();
|
|
1990
|
-
}
|
|
1991
|
-
}
|
|
1992
|
-
}
|
|
1993
|
-
else {
|
|
1994
|
-
for (const child of Object.values(control.controls)) {
|
|
1995
|
-
printErrorControls(child);
|
|
1996
|
-
}
|
|
1997
|
-
}
|
|
1998
|
-
}
|
|
1999
|
-
else {
|
|
2000
|
-
if (control.errors) {
|
|
2001
|
-
for (const [key, value] of Object.entries(control.errors)) {
|
|
2002
|
-
console.group(key);
|
|
2003
|
-
console.log(value);
|
|
2004
|
-
console.groupEnd();
|
|
2005
|
-
}
|
|
2006
|
-
}
|
|
2007
|
-
console.log('value: ', control.value);
|
|
2008
|
-
}
|
|
2009
|
-
console.groupEnd();
|
|
2010
|
-
}
|
|
2011
|
-
}
|
|
2012
|
-
printErrorControls(this.form);
|
|
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
|
+
});
|
|
2013
1971
|
}
|
|
2014
|
-
|
|
1972
|
+
});
|
|
1973
|
+
this.updateValueAndValidity(options);
|
|
1974
|
+
}
|
|
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);
|
|
1982
|
+
}
|
|
1983
|
+
disabledWhile(observable, options) {
|
|
1984
|
+
return controlDisabledWhile(this, observable, options);
|
|
1985
|
+
}
|
|
1986
|
+
enabledWhile(observable, options) {
|
|
1987
|
+
return controlEnabledWhile(this, observable, options);
|
|
1988
|
+
}
|
|
1989
|
+
mergeValidators(validators) {
|
|
1990
|
+
mergeControlValidators(this, validators);
|
|
1991
|
+
}
|
|
1992
|
+
mergeAsyncValidators(validators) {
|
|
1993
|
+
this.setAsyncValidators([
|
|
1994
|
+
...coerceArray(this.asyncValidator),
|
|
1995
|
+
...coerceArray(validators),
|
|
1996
|
+
]);
|
|
1997
|
+
this.updateValueAndValidity();
|
|
1998
|
+
}
|
|
1999
|
+
markAsTouched(opts) {
|
|
2000
|
+
super.markAsTouched(opts);
|
|
2001
|
+
this.touchChanges.next(true);
|
|
2002
|
+
}
|
|
2003
|
+
markAsUntouched(opts) {
|
|
2004
|
+
super.markAsUntouched(opts);
|
|
2005
|
+
this.touchChanges.next(false);
|
|
2006
|
+
}
|
|
2007
|
+
markAsPristine(opts) {
|
|
2008
|
+
super.markAsPristine(opts);
|
|
2009
|
+
this.dirtyChanges.next(false);
|
|
2010
|
+
}
|
|
2011
|
+
markAsDirty(opts) {
|
|
2012
|
+
super.markAsDirty(opts);
|
|
2013
|
+
this.dirtyChanges.next(true);
|
|
2014
|
+
}
|
|
2015
|
+
markAllAsDirty() {
|
|
2016
|
+
markAllDirty(this);
|
|
2017
|
+
}
|
|
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();
|
|
2015
2031
|
}
|
|
2016
|
-
return false;
|
|
2017
2032
|
}
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
if (
|
|
2021
|
-
|
|
2022
|
-
console.log('use the value from input initial');
|
|
2023
|
-
}
|
|
2024
|
-
form.patchValue(initial, { setInitialValue: true });
|
|
2033
|
+
setAsyncValidators(newValidator, updateValueAndValidity = true) {
|
|
2034
|
+
super.setAsyncValidators(newValidator);
|
|
2035
|
+
if (updateValueAndValidity) {
|
|
2036
|
+
super.updateValueAndValidity();
|
|
2025
2037
|
}
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
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;
|
|
2053
2088
|
}
|
|
2054
|
-
|
|
2055
|
-
this.
|
|
2056
|
-
this.loadingError$.next(error);
|
|
2057
|
-
this.loadFailed(error);
|
|
2058
|
-
this.loading$.disable();
|
|
2089
|
+
else {
|
|
2090
|
+
return [parent.controlPath, this.controlId].join('.');
|
|
2059
2091
|
}
|
|
2060
2092
|
}
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2093
|
+
}
|
|
2094
|
+
return this.controlId;
|
|
2095
|
+
}
|
|
2096
|
+
get fullControlPath() {
|
|
2097
|
+
const parent = this.parent;
|
|
2098
|
+
if (parent) {
|
|
2099
|
+
if (parent.fullControlPath) {
|
|
2100
|
+
return [parent.fullControlPath, this.controlId].join('.');
|
|
2066
2101
|
}
|
|
2067
2102
|
}
|
|
2103
|
+
return this.controlId;
|
|
2068
2104
|
}
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
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 });
|
|
2072
2127
|
}
|
|
2073
|
-
|
|
2074
|
-
|
|
2128
|
+
if (options.readonly) {
|
|
2129
|
+
this.readonly = true;
|
|
2075
2130
|
}
|
|
2131
|
+
this._initialState = formState;
|
|
2076
2132
|
}
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
else if (isDevMode()) {
|
|
2084
|
-
console.warn('The form loading failed for: ' + this.form.controlId);
|
|
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
|
+
});
|
|
2085
2139
|
}
|
|
2140
|
+
super.setValue(valueOrObservable, options);
|
|
2141
|
+
this._onSetValue.forEach((setValueFn) => setValueFn(valueOrObservable, options));
|
|
2086
2142
|
}
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
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;
|
|
2149
|
+
}
|
|
2150
|
+
});
|
|
2091
2151
|
}
|
|
2092
|
-
|
|
2093
|
-
|
|
2152
|
+
super.patchValue(valueOrObservable, options);
|
|
2153
|
+
if (options?.setInitialValue) {
|
|
2154
|
+
this._initialState = valueOrObservable;
|
|
2094
2155
|
}
|
|
2095
|
-
value = value ?? clone(this.form.value);
|
|
2096
|
-
return value;
|
|
2097
2156
|
}
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2157
|
+
disabledWhile(observable, options) {
|
|
2158
|
+
return controlDisabledWhile(this, observable, options);
|
|
2159
|
+
}
|
|
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);
|
|
2134
2197
|
}
|
|
2135
2198
|
else {
|
|
2136
|
-
|
|
2137
|
-
console.warn('The form submit method is not defined for: ' + this.form.controlId);
|
|
2138
|
-
}
|
|
2139
|
-
this.rxapSubmit.emit(value);
|
|
2140
|
-
this.submitSuccessful(value);
|
|
2199
|
+
super.reset(newState, options);
|
|
2141
2200
|
}
|
|
2142
2201
|
}
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
this.submitFailedMethod.call(error);
|
|
2202
|
+
setValidators(newValidator, updateValueAndValidity = true) {
|
|
2203
|
+
super.setValidators(newValidator);
|
|
2204
|
+
if (updateValueAndValidity) {
|
|
2205
|
+
super.updateValueAndValidity();
|
|
2148
2206
|
}
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2207
|
+
}
|
|
2208
|
+
setAsyncValidators(newValidator, updateValueAndValidity = true) {
|
|
2209
|
+
super.setAsyncValidators(newValidator);
|
|
2210
|
+
if (updateValueAndValidity) {
|
|
2211
|
+
super.updateValueAndValidity();
|
|
2152
2212
|
}
|
|
2153
2213
|
}
|
|
2154
|
-
|
|
2155
|
-
this
|
|
2156
|
-
|
|
2157
|
-
|
|
2214
|
+
validateOn(observableValidation) {
|
|
2215
|
+
return validateControlOn(this, observableValidation);
|
|
2216
|
+
}
|
|
2217
|
+
getError(errorCode) {
|
|
2218
|
+
return super.getError(errorCode);
|
|
2219
|
+
}
|
|
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);
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
|
|
2246
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
2247
|
+
class FormArrayControlManager {
|
|
2248
|
+
constructor(form, controlId) {
|
|
2249
|
+
this.form = form;
|
|
2250
|
+
this.controlId = controlId;
|
|
2251
|
+
}
|
|
2252
|
+
inserted(index, controlOrDefinition) {
|
|
2253
|
+
const controlContainer = this.form[this.controlId];
|
|
2254
|
+
if (Array.isArray(controlContainer)) {
|
|
2255
|
+
controlContainer.splice(index, 0, controlOrDefinition);
|
|
2158
2256
|
}
|
|
2159
|
-
else
|
|
2160
|
-
|
|
2161
|
-
this.form.controlId);
|
|
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!');
|
|
2162
2259
|
}
|
|
2163
2260
|
}
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
return obj && typeof obj.ngOnDestroy === 'function';
|
|
2261
|
+
removed(index) {
|
|
2262
|
+
const controlContainer = this.form[this.controlId];
|
|
2263
|
+
if (Array.isArray(controlContainer)) {
|
|
2264
|
+
controlContainer.splice(index, 1);
|
|
2169
2265
|
}
|
|
2170
|
-
|
|
2171
|
-
|
|
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!');
|
|
2172
2268
|
}
|
|
2173
2269
|
}
|
|
2174
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.16", 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 }); }
|
|
2175
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.2.16", 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: [
|
|
2176
|
-
{
|
|
2177
|
-
provide: ControlContainer,
|
|
2178
|
-
// ignore coverage
|
|
2179
|
-
useExisting: forwardRef(() => FormDirective),
|
|
2180
|
-
},
|
|
2181
|
-
// region form provider clear
|
|
2182
|
-
// form provider that are directly associated with the current form
|
|
2183
|
-
// are cleared to prevent that inner forms can access this providers
|
|
2184
|
-
// Example: The parent form has a submit method provider and the inner should
|
|
2185
|
-
// not have a submit method provider. If the parent submit method provider is
|
|
2186
|
-
// not cleared then the inner form uses the parent submit method provider on
|
|
2187
|
-
// submit
|
|
2188
|
-
{
|
|
2189
|
-
provide: RXAP_FORM_SUBMIT_METHOD,
|
|
2190
|
-
useValue: null,
|
|
2191
|
-
},
|
|
2192
|
-
{
|
|
2193
|
-
provide: RXAP_FORM_LOAD_METHOD,
|
|
2194
|
-
useValue: null,
|
|
2195
|
-
},
|
|
2196
|
-
{
|
|
2197
|
-
provide: RXAP_FORM_LOAD_FAILED_METHOD,
|
|
2198
|
-
useValue: null,
|
|
2199
|
-
},
|
|
2200
|
-
{
|
|
2201
|
-
provide: RXAP_FORM_LOAD_SUCCESSFUL_METHOD,
|
|
2202
|
-
useValue: null,
|
|
2203
|
-
},
|
|
2204
|
-
{
|
|
2205
|
-
provide: RXAP_FORM_SUBMIT_FAILED_METHOD,
|
|
2206
|
-
useValue: null,
|
|
2207
|
-
},
|
|
2208
|
-
{
|
|
2209
|
-
provide: RXAP_FORM_SUBMIT_SUCCESSFUL_METHOD,
|
|
2210
|
-
useValue: null,
|
|
2211
|
-
},
|
|
2212
|
-
{
|
|
2213
|
-
provide: RXAP_FORM_DEFINITION_BUILDER,
|
|
2214
|
-
useValue: null,
|
|
2215
|
-
},
|
|
2216
|
-
// endregion
|
|
2217
|
-
], exportAs: ["rxapForm"], usesInheritance: true, usesOnChanges: true, ngImport: i0 }); }
|
|
2218
2270
|
}
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
useValue: null,
|
|
2239
|
-
},
|
|
2240
|
-
{
|
|
2241
|
-
provide: RXAP_FORM_LOAD_METHOD,
|
|
2242
|
-
useValue: null,
|
|
2243
|
-
},
|
|
2244
|
-
{
|
|
2245
|
-
provide: RXAP_FORM_LOAD_FAILED_METHOD,
|
|
2246
|
-
useValue: null,
|
|
2247
|
-
},
|
|
2248
|
-
{
|
|
2249
|
-
provide: RXAP_FORM_LOAD_SUCCESSFUL_METHOD,
|
|
2250
|
-
useValue: null,
|
|
2251
|
-
},
|
|
2252
|
-
{
|
|
2253
|
-
provide: RXAP_FORM_SUBMIT_FAILED_METHOD,
|
|
2254
|
-
useValue: null,
|
|
2255
|
-
},
|
|
2256
|
-
{
|
|
2257
|
-
provide: RXAP_FORM_SUBMIT_SUCCESSFUL_METHOD,
|
|
2258
|
-
useValue: null,
|
|
2259
|
-
},
|
|
2260
|
-
{
|
|
2261
|
-
provide: RXAP_FORM_DEFINITION_BUILDER,
|
|
2262
|
-
useValue: null,
|
|
2263
|
-
},
|
|
2264
|
-
// endregion
|
|
2265
|
-
],
|
|
2266
|
-
host: { '(reset)': 'onReset()' },
|
|
2267
|
-
// eslint-disable-next-line @angular-eslint/no-outputs-metadata-property
|
|
2268
|
-
outputs: ['ngSubmit'],
|
|
2269
|
-
exportAs: 'rxapForm',
|
|
2270
|
-
standalone: true,
|
|
2271
|
-
}]
|
|
2272
|
-
}], ctorParameters: () => [{ type: i0.ChangeDetectorRef, decorators: [{
|
|
2273
|
-
type: Inject,
|
|
2274
|
-
args: [ChangeDetectorRef]
|
|
2275
|
-
}] }, { type: undefined, decorators: [{
|
|
2276
|
-
type: Optional
|
|
2277
|
-
}, {
|
|
2278
|
-
type: Inject,
|
|
2279
|
-
args: [RXAP_FORM_DEFINITION]
|
|
2280
|
-
}] }, { type: undefined, decorators: [{
|
|
2281
|
-
type: SkipSelf
|
|
2282
|
-
}, {
|
|
2283
|
-
type: Optional
|
|
2284
|
-
}, {
|
|
2285
|
-
type: Inject,
|
|
2286
|
-
args: [RXAP_FORM_SUBMIT_METHOD]
|
|
2287
|
-
}] }, { type: undefined, decorators: [{
|
|
2288
|
-
type: SkipSelf
|
|
2289
|
-
}, {
|
|
2290
|
-
type: Optional
|
|
2291
|
-
}, {
|
|
2292
|
-
type: Inject,
|
|
2293
|
-
args: [RXAP_FORM_LOAD_METHOD]
|
|
2294
|
-
}] }, { type: undefined, decorators: [{
|
|
2295
|
-
type: SkipSelf
|
|
2296
|
-
}, {
|
|
2297
|
-
type: Optional
|
|
2298
|
-
}, {
|
|
2299
|
-
type: Inject,
|
|
2300
|
-
args: [RXAP_FORM_LOAD_FAILED_METHOD]
|
|
2301
|
-
}] }, { type: undefined, decorators: [{
|
|
2302
|
-
type: SkipSelf
|
|
2303
|
-
}, {
|
|
2304
|
-
type: Optional
|
|
2305
|
-
}, {
|
|
2306
|
-
type: Inject,
|
|
2307
|
-
args: [RXAP_FORM_LOAD_SUCCESSFUL_METHOD]
|
|
2308
|
-
}] }, { type: undefined, decorators: [{
|
|
2309
|
-
type: SkipSelf
|
|
2310
|
-
}, {
|
|
2311
|
-
type: Optional
|
|
2312
|
-
}, {
|
|
2313
|
-
type: Inject,
|
|
2314
|
-
args: [RXAP_FORM_SUBMIT_FAILED_METHOD]
|
|
2315
|
-
}] }, { type: undefined, decorators: [{
|
|
2316
|
-
type: SkipSelf
|
|
2317
|
-
}, {
|
|
2318
|
-
type: Optional
|
|
2319
|
-
}, {
|
|
2320
|
-
type: Inject,
|
|
2321
|
-
args: [RXAP_FORM_SUBMIT_SUCCESSFUL_METHOD]
|
|
2322
|
-
}] }, { type: RxapFormBuilder, decorators: [{
|
|
2323
|
-
type: SkipSelf
|
|
2324
|
-
}, {
|
|
2325
|
-
type: Optional
|
|
2326
|
-
}, {
|
|
2327
|
-
type: Inject,
|
|
2328
|
-
args: [RXAP_FORM_DEFINITION_BUILDER]
|
|
2329
|
-
}] }, { type: i2.LoadingIndicatorService, decorators: [{
|
|
2330
|
-
type: Optional
|
|
2331
|
-
}, {
|
|
2332
|
-
type: Inject,
|
|
2333
|
-
args: [LoadingIndicatorService]
|
|
2334
|
-
}] }, { type: undefined, decorators: [{
|
|
2335
|
-
type: Optional
|
|
2336
|
-
}, {
|
|
2337
|
-
type: Inject,
|
|
2338
|
-
args: [RXAP_FORM_CONTEXT]
|
|
2339
|
-
}] }, { type: undefined, decorators: [{
|
|
2340
|
-
type: Optional
|
|
2341
|
-
}, {
|
|
2342
|
-
type: Inject,
|
|
2343
|
-
args: [RXAP_FORM_INITIAL_STATE]
|
|
2344
|
-
}] }], propDecorators: { rxapSubmit: [{
|
|
2345
|
-
type: Output
|
|
2346
|
-
}], invalidSubmit: [{
|
|
2347
|
-
type: Output
|
|
2348
|
-
}], submitSuccessful$: [{
|
|
2349
|
-
type: Output,
|
|
2350
|
-
args: ['submitSuccessful']
|
|
2351
|
-
}], submitting: [{
|
|
2352
|
-
type: HostBinding,
|
|
2353
|
-
args: ['class.rxap-submitting']
|
|
2354
|
-
}], submitError: [{
|
|
2355
|
-
type: HostBinding,
|
|
2356
|
-
args: ['class.rxap-submit-error']
|
|
2357
|
-
}], loading: [{
|
|
2358
|
-
type: HostBinding,
|
|
2359
|
-
args: ['class.rxap-loading']
|
|
2360
|
-
}], loaded: [{
|
|
2361
|
-
type: HostBinding,
|
|
2362
|
-
args: ['class.rxap-loaded']
|
|
2363
|
-
}], loadingError: [{
|
|
2364
|
-
type: HostBinding,
|
|
2365
|
-
args: ['class.rxap-loading-error']
|
|
2366
|
-
}], useFormDefinition: [{
|
|
2367
|
-
type: Input,
|
|
2368
|
-
args: ['rxapForm']
|
|
2369
|
-
}], submitMethod: [{
|
|
2370
|
-
type: Input
|
|
2371
|
-
}], loadMethod: [{
|
|
2372
|
-
type: Input
|
|
2373
|
-
}], loadFailedMethod: [{
|
|
2374
|
-
type: Input
|
|
2375
|
-
}], loadSuccessfulMethod: [{
|
|
2376
|
-
type: Input
|
|
2377
|
-
}], submitFailedMethod: [{
|
|
2378
|
-
type: Input
|
|
2379
|
-
}], submitSuccessfulMethod: [{
|
|
2380
|
-
type: Input
|
|
2381
|
-
}] } });
|
|
2382
|
-
|
|
2383
|
-
class FormLoadedDirective {
|
|
2384
|
-
constructor(formDirective, template, viewContainerRef) {
|
|
2385
|
-
this.formDirective = formDirective;
|
|
2386
|
-
this.template = template;
|
|
2387
|
-
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);
|
|
2388
2290
|
}
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
this.
|
|
2392
|
-
|
|
2393
|
-
|
|
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
|
+
}
|
|
2394
2343
|
}
|
|
2395
|
-
}
|
|
2396
|
-
|
|
2397
|
-
ngOnDestroy() {
|
|
2398
|
-
this.subscription?.unsubscribe();
|
|
2399
|
-
}
|
|
2400
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.16", ngImport: i0, type: FormLoadedDirective, deps: [{ token: FormDirective }, { token: TemplateRef }, { token: ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
2401
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.16", type: FormLoadedDirective, isStandalone: true, selector: "[rxapFormLoaded]", ngImport: i0 }); }
|
|
2402
|
-
}
|
|
2403
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.16", ngImport: i0, type: FormLoadedDirective, decorators: [{
|
|
2404
|
-
type: Directive,
|
|
2405
|
-
args: [{
|
|
2406
|
-
selector: '[rxapFormLoaded]',
|
|
2407
|
-
standalone: true,
|
|
2408
|
-
}]
|
|
2409
|
-
}], ctorParameters: () => [{ type: FormDirective, decorators: [{
|
|
2410
|
-
type: Inject,
|
|
2411
|
-
args: [FormDirective]
|
|
2412
|
-
}] }, { type: i0.TemplateRef, decorators: [{
|
|
2413
|
-
type: Inject,
|
|
2414
|
-
args: [TemplateRef]
|
|
2415
|
-
}] }, { type: i0.ViewContainerRef, decorators: [{
|
|
2416
|
-
type: Inject,
|
|
2417
|
-
args: [ViewContainerRef]
|
|
2418
|
-
}] }] });
|
|
2419
|
-
|
|
2420
|
-
class FormLoadingErrorDirective {
|
|
2421
|
-
constructor(formDirective, template, viewContainerRef) {
|
|
2422
|
-
this.formDirective = formDirective;
|
|
2423
|
-
this.template = template;
|
|
2424
|
-
this.viewContainerRef = viewContainerRef;
|
|
2344
|
+
}
|
|
2345
|
+
return form;
|
|
2425
2346
|
}
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
this.
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
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
|
+
}
|
|
2433
2371
|
}
|
|
2434
|
-
|
|
2435
|
-
this.
|
|
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
|
+
}
|
|
2436
2396
|
}
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
}
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
args: [ViewContainerRef]
|
|
2455
|
-
}] }] });
|
|
2456
|
-
|
|
2457
|
-
class FormLoadingDirective {
|
|
2458
|
-
constructor(formDirective, template, viewContainerRef) {
|
|
2459
|
-
this.formDirective = formDirective;
|
|
2460
|
-
this.template = template;
|
|
2461
|
-
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
|
+
}
|
|
2462
2414
|
}
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
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
|
+
}
|
|
2468
2434
|
}
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
selector: '[rxapFormLoading]',
|
|
2481
|
-
standalone: true,
|
|
2482
|
-
}]
|
|
2483
|
-
}], ctorParameters: () => [{ type: FormDirective, decorators: [{
|
|
2484
|
-
type: Inject,
|
|
2485
|
-
args: [FormDirective]
|
|
2486
|
-
}] }, { type: i0.TemplateRef, decorators: [{
|
|
2487
|
-
type: Inject,
|
|
2488
|
-
args: [TemplateRef]
|
|
2489
|
-
}] }, { type: i0.ViewContainerRef, decorators: [{
|
|
2490
|
-
type: Inject,
|
|
2491
|
-
args: [ViewContainerRef]
|
|
2492
|
-
}] }] });
|
|
2493
|
-
|
|
2494
|
-
class FormResetDirective extends ConfirmClick {
|
|
2495
|
-
constructor(formDirective) {
|
|
2496
|
-
super();
|
|
2497
|
-
this.formDirective = formDirective;
|
|
2498
|
-
this.type = 'button';
|
|
2499
|
-
}
|
|
2500
|
-
execute() {
|
|
2501
|
-
this.formDirective.reset();
|
|
2502
|
-
}
|
|
2503
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.16", ngImport: i0, type: FormResetDirective, deps: [{ token: FormDirective }], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
2504
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.16", type: FormResetDirective, isStandalone: true, selector: "[rxapFormReset]", inputs: { type: "type" }, host: { listeners: { "click": "onClick()", "confirmed": "onConfirm()" }, properties: { "type": "this.type" } }, usesInheritance: true, ngImport: i0 }); }
|
|
2505
|
-
}
|
|
2506
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.16", ngImport: i0, type: FormResetDirective, decorators: [{
|
|
2507
|
-
type: Directive,
|
|
2508
|
-
args: [{
|
|
2509
|
-
selector: '[rxapFormReset]',
|
|
2510
|
-
host: {
|
|
2511
|
-
'(click)': 'onClick()',
|
|
2512
|
-
'(confirmed)': 'onConfirm()',
|
|
2513
|
-
},
|
|
2514
|
-
standalone: true,
|
|
2515
|
-
}]
|
|
2516
|
-
}], ctorParameters: () => [{ type: FormDirective, decorators: [{
|
|
2517
|
-
type: Inject,
|
|
2518
|
-
args: [FormDirective]
|
|
2519
|
-
}] }], propDecorators: { type: [{
|
|
2520
|
-
type: HostBinding,
|
|
2521
|
-
args: ['type']
|
|
2522
|
-
}, {
|
|
2523
|
-
type: Input
|
|
2524
|
-
}] } });
|
|
2525
|
-
|
|
2526
|
-
class FormSubmitFailedDirective {
|
|
2527
|
-
constructor(formDirective, template, viewContainerRef) {
|
|
2528
|
-
this.formDirective = formDirective;
|
|
2529
|
-
this.template = template;
|
|
2530
|
-
this.viewContainerRef = viewContainerRef;
|
|
2531
|
-
}
|
|
2532
|
-
ngAfterViewInit() {
|
|
2533
|
-
this.subscription = this.formDirective.submitError$.pipe(tap(error => {
|
|
2534
|
-
this.viewContainerRef.clear();
|
|
2535
|
-
if (error !== null) {
|
|
2536
|
-
this.viewContainerRef.createEmbeddedView(this.template, { $implicit: error });
|
|
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
|
+
}
|
|
2537
2446
|
}
|
|
2538
|
-
|
|
2447
|
+
// set the form control instance to the form definition instance
|
|
2448
|
+
Reflect.set(form, controlId, control);
|
|
2449
|
+
}
|
|
2539
2450
|
}
|
|
2540
|
-
|
|
2541
|
-
|
|
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;
|
|
2542
2470
|
}
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
constructor(formDirective, template, viewContainerRef) {
|
|
2565
|
-
this.formDirective = formDirective;
|
|
2566
|
-
this.template = template;
|
|
2567
|
-
this.viewContainerRef = viewContainerRef;
|
|
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;
|
|
2568
2492
|
}
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
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;
|
|
2574
2514
|
}
|
|
2575
|
-
|
|
2576
|
-
|
|
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;
|
|
2577
2545
|
}
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
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;
|
|
2603
2576
|
}
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
this.viewContainerRef.createEmbeddedView(this.template, { $implicit: result });
|
|
2608
|
-
})).subscribe();
|
|
2577
|
+
extractControlChanges() {
|
|
2578
|
+
return (getMetadata(MetadataKeys.CONTROL_CHANGES, this.definition.prototype) ??
|
|
2579
|
+
new Map());
|
|
2609
2580
|
}
|
|
2610
|
-
|
|
2611
|
-
this.
|
|
2581
|
+
extractControlSetValue() {
|
|
2582
|
+
return (getMetadata(MetadataKeys.CONTROL_SET_VALUE, this.definition.prototype) ??
|
|
2583
|
+
new Map());
|
|
2612
2584
|
}
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.16", ngImport: i0, type: FormSubmitSuccessfulDirective, decorators: [{
|
|
2617
|
-
type: Directive,
|
|
2618
|
-
args: [{
|
|
2619
|
-
selector: '[rxapFormSubmitSuccessful]',
|
|
2620
|
-
standalone: true,
|
|
2621
|
-
}]
|
|
2622
|
-
}], ctorParameters: () => [{ type: FormDirective, decorators: [{
|
|
2623
|
-
type: Inject,
|
|
2624
|
-
args: [FormDirective]
|
|
2625
|
-
}] }, { type: i0.TemplateRef, decorators: [{
|
|
2626
|
-
type: Inject,
|
|
2627
|
-
args: [TemplateRef]
|
|
2628
|
-
}] }, { type: i0.ViewContainerRef, decorators: [{
|
|
2629
|
-
type: Inject,
|
|
2630
|
-
args: [ViewContainerRef]
|
|
2631
|
-
}] }] });
|
|
2632
|
-
|
|
2633
|
-
class FormSubmitDirective extends ConfirmClick {
|
|
2634
|
-
constructor(formDirective, router = null) {
|
|
2635
|
-
super();
|
|
2636
|
-
this.formDirective = formDirective;
|
|
2637
|
-
this.router = router;
|
|
2638
|
-
this.type = input('button');
|
|
2639
|
-
this.resetAfterSubmit = input(false, { transform: coerceBoolean });
|
|
2640
|
-
this.navigateAfterSubmit = input();
|
|
2641
|
-
this.afterSubmit = output();
|
|
2642
|
-
this.disableWhileSubmitting = input(true);
|
|
2643
|
-
this.submitting = toSignal(this.formDirective.submitting$, { initialValue: false });
|
|
2644
|
-
this.disabled = computed(() => this.disableWhileSubmitting() && this.submitting());
|
|
2585
|
+
extractValidators() {
|
|
2586
|
+
return (getMetadata(MetadataKeys.CONTROL_VALIDATORS, this.definition.prototype) ??
|
|
2587
|
+
new Map());
|
|
2645
2588
|
}
|
|
2646
|
-
|
|
2647
|
-
this.
|
|
2648
|
-
this.formDirective.form.markAllAsTouched();
|
|
2649
|
-
this.formDirective.cdr.markForCheck();
|
|
2650
|
-
this.subscription = this.formDirective.rxapSubmit.pipe(take(1), tap(value => {
|
|
2651
|
-
const clonedValue = clone(value);
|
|
2652
|
-
this.afterSubmit.emit(clonedValue);
|
|
2653
|
-
if (this.resetAfterSubmit()) {
|
|
2654
|
-
this.formDirective.reset();
|
|
2655
|
-
}
|
|
2656
|
-
const navigateAfterSubmit = this.navigateAfterSubmit();
|
|
2657
|
-
if (Array.isArray(navigateAfterSubmit)) {
|
|
2658
|
-
if (!this.router) {
|
|
2659
|
-
throw new Error('Could not resolve the router!');
|
|
2660
|
-
}
|
|
2661
|
-
return this.router.navigate(navigateAfterSubmit);
|
|
2662
|
-
}
|
|
2663
|
-
return Promise.resolve();
|
|
2664
|
-
})).subscribe();
|
|
2665
|
-
this.formDirective.onSubmit(new Event('submit'));
|
|
2589
|
+
extractAsyncValidators() {
|
|
2590
|
+
return (getMetadata(MetadataKeys.CONTROL_ASYNC_VALIDATORS, this.definition.prototype) ?? new Map());
|
|
2666
2591
|
}
|
|
2667
|
-
|
|
2668
|
-
this.
|
|
2592
|
+
extractArrayGroups() {
|
|
2593
|
+
return (getMetadata(MetadataKeys.FORM_ARRAY_GROUPS, this.definition.prototype) ??
|
|
2594
|
+
new Map());
|
|
2669
2595
|
}
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
}
|
|
2673
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.16", ngImport: i0, type: FormSubmitDirective, decorators: [{
|
|
2674
|
-
type: Directive,
|
|
2675
|
-
args: [{
|
|
2676
|
-
selector: '[rxapFormSubmit]',
|
|
2677
|
-
host: {
|
|
2678
|
-
'(click)': 'onClick()',
|
|
2679
|
-
'(confirmed)': 'onConfirm()',
|
|
2680
|
-
'[disabled]': 'disabled()',
|
|
2681
|
-
'[type]': 'type()',
|
|
2682
|
-
},
|
|
2683
|
-
standalone: true,
|
|
2684
|
-
exportAs: 'rxapFormSubmit',
|
|
2685
|
-
}]
|
|
2686
|
-
}], ctorParameters: () => [{ type: FormDirective, decorators: [{
|
|
2687
|
-
type: Inject,
|
|
2688
|
-
args: [FormDirective]
|
|
2689
|
-
}] }, { type: i2$1.Router, decorators: [{
|
|
2690
|
-
type: Optional
|
|
2691
|
-
}, {
|
|
2692
|
-
type: Inject,
|
|
2693
|
-
args: [Router]
|
|
2694
|
-
}] }] });
|
|
2695
|
-
|
|
2696
|
-
class FormSubmittingDirective {
|
|
2697
|
-
constructor(formDirective, template, viewContainerRef) {
|
|
2698
|
-
this.formDirective = formDirective;
|
|
2699
|
-
this.template = template;
|
|
2700
|
-
this.viewContainerRef = viewContainerRef;
|
|
2596
|
+
extractArrayControls() {
|
|
2597
|
+
return (getMetadata(MetadataKeys.FORM_ARRAY_CONTROLS, this.definition.prototype) ?? new Map());
|
|
2701
2598
|
}
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
if (loading) {
|
|
2706
|
-
this.viewContainerRef.createEmbeddedView(this.template);
|
|
2707
|
-
}
|
|
2708
|
-
})).subscribe();
|
|
2599
|
+
extractGroups() {
|
|
2600
|
+
return (getMetadata(MetadataKeys.FORM_GROUPS, this.definition.prototype) ??
|
|
2601
|
+
new Map());
|
|
2709
2602
|
}
|
|
2710
|
-
|
|
2711
|
-
this.
|
|
2603
|
+
extractControls() {
|
|
2604
|
+
return (getMetadata(MetadataKeys.FORM_CONTROLS, this.definition.prototype) ??
|
|
2605
|
+
new Map());
|
|
2712
2606
|
}
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
type: Directive,
|
|
2718
|
-
args: [{
|
|
2719
|
-
selector: '[rxapFormSubmitting]',
|
|
2720
|
-
standalone: true,
|
|
2721
|
-
}]
|
|
2722
|
-
}], ctorParameters: () => [{ type: FormDirective, decorators: [{
|
|
2723
|
-
type: Inject,
|
|
2724
|
-
args: [FormDirective]
|
|
2725
|
-
}] }, { type: i0.TemplateRef, decorators: [{
|
|
2726
|
-
type: Inject,
|
|
2727
|
-
args: [TemplateRef]
|
|
2728
|
-
}] }, { type: i0.ViewContainerRef, decorators: [{
|
|
2729
|
-
type: Inject,
|
|
2730
|
-
args: [ViewContainerRef]
|
|
2731
|
-
}] }] });
|
|
2732
|
-
|
|
2733
|
-
class ParentControlContainerDirective {
|
|
2734
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.16", ngImport: i0, type: ParentControlContainerDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
2735
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.16", type: ParentControlContainerDirective, isStandalone: true, selector: "[formControlName][parentControlContainer],[formControlGroup][parentControlContainer]", providers: [
|
|
2736
|
-
{
|
|
2737
|
-
provide: ControlContainer,
|
|
2738
|
-
useExisting: ControlContainer,
|
|
2739
|
-
},
|
|
2740
|
-
], ngImport: i0 }); }
|
|
2741
|
-
}
|
|
2742
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.16", ngImport: i0, type: ParentControlContainerDirective, decorators: [{
|
|
2743
|
-
type: Directive,
|
|
2744
|
-
args: [{
|
|
2745
|
-
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
2746
|
-
selector: '[formControlName][parentControlContainer],[formControlGroup][parentControlContainer]',
|
|
2747
|
-
providers: [
|
|
2748
|
-
{
|
|
2749
|
-
provide: ControlContainer,
|
|
2750
|
-
useExisting: ControlContainer,
|
|
2751
|
-
},
|
|
2752
|
-
],
|
|
2753
|
-
standalone: true,
|
|
2754
|
-
}]
|
|
2755
|
-
}] });
|
|
2756
|
-
|
|
2757
|
-
class RxapFormsModule {
|
|
2758
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.16", ngImport: i0, type: RxapFormsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
2759
|
-
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.16", ngImport: i0, type: RxapFormsModule, imports: [FormDirective,
|
|
2760
|
-
FormSubmitFailedDirective,
|
|
2761
|
-
FormLoadingDirective,
|
|
2762
|
-
FormSubmittingDirective,
|
|
2763
|
-
FormLoadingErrorDirective,
|
|
2764
|
-
FormLoadedDirective,
|
|
2765
|
-
FormControlErrorDirective,
|
|
2766
|
-
FormControlMarkDirtyDirective,
|
|
2767
|
-
FormControlMarkTouchedDirective,
|
|
2768
|
-
FormControlMarkUntouchedDirective,
|
|
2769
|
-
FormControlMarkPristineDirective,
|
|
2770
|
-
FormSubmitDirective,
|
|
2771
|
-
FormGroupNameDirective,
|
|
2772
|
-
FormControlNameDirective,
|
|
2773
|
-
ParentControlContainerDirective,
|
|
2774
|
-
FormSubmitSuccessfulDirective,
|
|
2775
|
-
FormSubmitInvalidDirective], exports: [FormDirective,
|
|
2776
|
-
FormSubmitFailedDirective,
|
|
2777
|
-
FormLoadingDirective,
|
|
2778
|
-
FormSubmittingDirective,
|
|
2779
|
-
FormLoadingErrorDirective,
|
|
2780
|
-
FormLoadedDirective,
|
|
2781
|
-
FormControlErrorDirective,
|
|
2782
|
-
FormControlMarkDirtyDirective,
|
|
2783
|
-
FormControlMarkTouchedDirective,
|
|
2784
|
-
FormControlMarkUntouchedDirective,
|
|
2785
|
-
FormControlMarkPristineDirective,
|
|
2786
|
-
FormSubmitDirective,
|
|
2787
|
-
FormGroupNameDirective,
|
|
2788
|
-
FormControlNameDirective,
|
|
2789
|
-
ParentControlContainerDirective,
|
|
2790
|
-
FormSubmitSuccessfulDirective,
|
|
2791
|
-
FormSubmitInvalidDirective] }); }
|
|
2792
|
-
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.16", ngImport: i0, type: RxapFormsModule }); }
|
|
2793
|
-
}
|
|
2794
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.16", ngImport: i0, type: RxapFormsModule, decorators: [{
|
|
2795
|
-
type: NgModule,
|
|
2796
|
-
args: [{
|
|
2797
|
-
imports: [
|
|
2798
|
-
FormDirective,
|
|
2799
|
-
FormSubmitFailedDirective,
|
|
2800
|
-
FormLoadingDirective,
|
|
2801
|
-
FormSubmittingDirective,
|
|
2802
|
-
FormLoadingErrorDirective,
|
|
2803
|
-
FormLoadedDirective,
|
|
2804
|
-
FormControlErrorDirective,
|
|
2805
|
-
FormControlMarkDirtyDirective,
|
|
2806
|
-
FormControlMarkTouchedDirective,
|
|
2807
|
-
FormControlMarkUntouchedDirective,
|
|
2808
|
-
FormControlMarkPristineDirective,
|
|
2809
|
-
FormSubmitDirective,
|
|
2810
|
-
FormGroupNameDirective,
|
|
2811
|
-
FormControlNameDirective,
|
|
2812
|
-
ParentControlContainerDirective,
|
|
2813
|
-
FormSubmitSuccessfulDirective,
|
|
2814
|
-
FormSubmitInvalidDirective,
|
|
2815
|
-
],
|
|
2816
|
-
exports: [
|
|
2817
|
-
FormDirective,
|
|
2818
|
-
FormSubmitFailedDirective,
|
|
2819
|
-
FormLoadingDirective,
|
|
2820
|
-
FormSubmittingDirective,
|
|
2821
|
-
FormLoadingErrorDirective,
|
|
2822
|
-
FormLoadedDirective,
|
|
2823
|
-
FormControlErrorDirective,
|
|
2824
|
-
FormControlMarkDirtyDirective,
|
|
2825
|
-
FormControlMarkTouchedDirective,
|
|
2826
|
-
FormControlMarkUntouchedDirective,
|
|
2827
|
-
FormControlMarkPristineDirective,
|
|
2828
|
-
FormSubmitDirective,
|
|
2829
|
-
FormGroupNameDirective,
|
|
2830
|
-
FormControlNameDirective,
|
|
2831
|
-
ParentControlContainerDirective,
|
|
2832
|
-
FormSubmitSuccessfulDirective,
|
|
2833
|
-
FormSubmitInvalidDirective,
|
|
2834
|
-
],
|
|
2835
|
-
}]
|
|
2836
|
-
}] });
|
|
2837
|
-
|
|
2838
|
-
function ToFormMethod(call) {
|
|
2839
|
-
return { call };
|
|
2840
|
-
}
|
|
2841
|
-
/**
|
|
2842
|
-
* @deprecated use ToFormMethod instead
|
|
2843
|
-
*
|
|
2844
|
-
* @param call the call method implementation
|
|
2845
|
-
*/
|
|
2846
|
-
function ToFormSubmitMethod(call) {
|
|
2847
|
-
return ToFormMethod(call);
|
|
2848
|
-
}
|
|
2849
|
-
|
|
2850
|
-
function ControlAsyncValidator(...controlIds) {
|
|
2851
|
-
return function (target, propertyKey) {
|
|
2852
|
-
for (const controlId of controlIds) {
|
|
2853
|
-
setMetadataMapSet(controlId, propertyKey, MetadataKeys.CONTROL_ASYNC_VALIDATORS, target);
|
|
2854
|
-
}
|
|
2855
|
-
};
|
|
2856
|
-
}
|
|
2857
|
-
|
|
2858
|
-
function ControlChange(...controlIds) {
|
|
2859
|
-
return function (target, propertyKey) {
|
|
2860
|
-
for (const controlId of controlIds) {
|
|
2861
|
-
setMetadataMapSet(controlId, propertyKey, MetadataKeys.CONTROL_CHANGES, target);
|
|
2607
|
+
extractFormOptions() {
|
|
2608
|
+
const options = GetDefinitionMetadata(this.definition);
|
|
2609
|
+
if (!options || !options['id']) {
|
|
2610
|
+
throw new Error('Ensure that the @UseForm decorator is used.');
|
|
2862
2611
|
}
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
function ControlSetValue(controlId, options = {}) {
|
|
2867
|
-
return function (target, propertyKey) {
|
|
2868
|
-
setMetadataMapSet(controlId, {
|
|
2869
|
-
...options,
|
|
2870
|
-
propertyKey,
|
|
2871
|
-
}, MetadataKeys.CONTROL_SET_VALUE, target);
|
|
2872
|
-
};
|
|
2873
|
-
}
|
|
2874
|
-
|
|
2875
|
-
function ControlValidator(...controlIds) {
|
|
2876
|
-
return function (target, propertyKey) {
|
|
2877
|
-
for (const controlId of controlIds) {
|
|
2878
|
-
setMetadataMapSet(controlId, propertyKey, MetadataKeys.CONTROL_VALIDATORS, target);
|
|
2612
|
+
if (!options['providers']) {
|
|
2613
|
+
options['providers'] = [];
|
|
2879
2614
|
}
|
|
2880
|
-
|
|
2881
|
-
}
|
|
2882
|
-
|
|
2883
|
-
function RxapForm(optionsOrId, className = 'FormDefinition', packageName = '@rxap/forms') {
|
|
2884
|
-
return function (target) {
|
|
2885
|
-
DefinitionMetadata(optionsOrId, className, packageName)(target);
|
|
2886
|
-
};
|
|
2887
|
-
}
|
|
2888
|
-
|
|
2889
|
-
function UseFormArrayGroup(definition, options = {}) {
|
|
2890
|
-
return function (target, propertyKey) {
|
|
2891
|
-
setMetadataMap(propertyKey, {
|
|
2892
|
-
...options,
|
|
2893
|
-
definition,
|
|
2894
|
-
}, MetadataKeys.FORM_ARRAY_GROUPS, target);
|
|
2895
|
-
};
|
|
2896
|
-
}
|
|
2897
|
-
function UseFormArrayControl(options = {}) {
|
|
2898
|
-
return function (target, propertyKey) {
|
|
2899
|
-
setMetadataMap(propertyKey, options, MetadataKeys.FORM_ARRAY_CONTROLS, target);
|
|
2900
|
-
};
|
|
2901
|
-
}
|
|
2902
|
-
|
|
2903
|
-
function UseFormControl(options = {}) {
|
|
2904
|
-
return function (target, propertyKey) {
|
|
2905
|
-
setMetadataMap(propertyKey, options, MetadataKeys.FORM_CONTROLS, target);
|
|
2906
|
-
};
|
|
2907
|
-
}
|
|
2908
|
-
|
|
2909
|
-
function UseFormGroup(definition, options = {}) {
|
|
2910
|
-
return function (target, propertyKey) {
|
|
2911
|
-
setMetadataMap(propertyKey, {
|
|
2912
|
-
...options,
|
|
2913
|
-
definition,
|
|
2914
|
-
}, MetadataKeys.FORM_GROUPS, target);
|
|
2915
|
-
};
|
|
2916
|
-
}
|
|
2917
|
-
|
|
2918
|
-
class ControlValueAccessor {
|
|
2919
|
-
constructor() {
|
|
2920
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
2921
|
-
this.onChange = (value) => {
|
|
2922
|
-
};
|
|
2923
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
2924
|
-
this.onTouched = () => {
|
|
2925
|
-
};
|
|
2926
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
2927
|
-
this.setDisabledState = (isDisabled) => {
|
|
2928
|
-
};
|
|
2929
|
-
}
|
|
2930
|
-
registerOnChange(fn) {
|
|
2931
|
-
this.onChange = fn;
|
|
2932
|
-
}
|
|
2933
|
-
registerOnTouched(fn) {
|
|
2934
|
-
this.onTouched = fn;
|
|
2615
|
+
return options;
|
|
2935
2616
|
}
|
|
2936
2617
|
}
|
|
2937
2618
|
|
|
@@ -2942,5 +2623,5 @@ class ControlValueAccessor {
|
|
|
2942
2623
|
* Generated bundle index. Do not edit.
|
|
2943
2624
|
*/
|
|
2944
2625
|
|
|
2945
|
-
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,
|
|
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 };
|
|
2946
2627
|
//# sourceMappingURL=rxap-forms.mjs.map
|