diff --git a/src/app/features/deposit/components/presentationals/deposit-form/deposit-form.presentational.ts b/src/app/features/deposit/components/presentationals/deposit-form/deposit-form.presentational.ts index 7e0b4cee7e0477346094e67945803daeb879c384..3b5f5629ada866a4b5580621dc14dbd082c74125 100644 --- a/src/app/features/deposit/components/presentationals/deposit-form/deposit-form.presentational.ts +++ b/src/app/features/deposit/components/presentationals/deposit-form/deposit-form.presentational.ts @@ -130,7 +130,7 @@ export class DepositFormPresentational extends SharedAbstractFormPresentational< if (accessLevel === AccessEnum.PUBLIC) { licenseFormControl.setValidators([Validators.required]); } else { - licenseFormControl.setValidators(null); + licenseFormControl.setValidators([]); } licenseFormControl.updateValueAndValidity(); }), diff --git a/src/app/shared/components/presentationals/shared-searchable-single-select/shared-searchable-single-select.presentational.ts b/src/app/shared/components/presentationals/shared-searchable-single-select/shared-searchable-single-select.presentational.ts index 77c852c914b69767a00db93043cfbeed74e0237e..765699e82c3e5545d1e2e6e89f604c7f2b7da7f4 100644 --- a/src/app/shared/components/presentationals/shared-searchable-single-select/shared-searchable-single-select.presentational.ts +++ b/src/app/shared/components/presentationals/shared-searchable-single-select/shared-searchable-single-select.presentational.ts @@ -42,6 +42,7 @@ import { isEmptyString, isNonEmptyString, isNullOrUndefined, + isTrue, ObservableUtil, PropertyName, ResourceNameSpace, @@ -92,6 +93,8 @@ export class SharedSearchableSingleSelectPresentational extends SharedAbstractPr currentObs: Observable<any>; floatLabel: FloatLabelType; + alreadyInit: boolean = false; + get formValidationHelper(): typeof FormValidationHelper { return FormValidationHelper; } @@ -110,9 +113,15 @@ export class SharedSearchableSingleSelectPresentational extends SharedAbstractPr } ngOnInit(): void { + if (isTrue(this.alreadyInit)) { + // When validator is updated, the ngOnInit is call a new time + // This hack prevent this to happen (case with deposit license validator impacted by access level + return; + } this._initFormLabel(); this._dispatchGetActionToRetrieveLabel(); this._observeLabelUpdate(); + this.alreadyInit = true; } private _initFormLabel(): void { @@ -248,8 +257,8 @@ export class SharedSearchableSingleSelectPresentational extends SharedAbstractPr } clearValue($event: MouseEvent): void { - this.formControl.setValue(undefined); - this.formLabel.get(this.formDefinition.value).setValue(undefined); + this.formControl.setValue(""); + this.formLabel.get(this.formDefinition.value).setValue(null); $event.stopPropagation(); this.computeFloatLabel(); } diff --git a/src/app/shared/directives/shared-validation/shared-validation.directive.ts b/src/app/shared/directives/shared-validation/shared-validation.directive.ts index 088ae55b1aa7d0586374a7f246fa2afff57719c0..8636f92631e1fab3a046779d1017eebc23158338 100644 --- a/src/app/shared/directives/shared-validation/shared-validation.directive.ts +++ b/src/app/shared/directives/shared-validation/shared-validation.directive.ts @@ -21,6 +21,7 @@ import { import { isArray, isEmptyArray, + isFalse, isNullOrUndefined, ObjectUtil, } from "solidify-frontend"; @@ -57,10 +58,16 @@ export class SharedValidationDirective extends SharedAbstractDirective implement ngOnInit(): void { FormValidationHelper.initMetadataErrors(this._ngControl.control); + let isDetectChangesFromParent = false; // This hack prevent in most case infinity loop call stack error due to parent update change + // TODO Find a clean way working at 100%. In some case we get call stack error when change access level in deposit create form... this.subscribe(this._ngControl.control.parent.statusChanges.pipe( tap(validity => { - this._changeDetector.detectChanges(); + if (isFalse(isDetectChangesFromParent)) { + // Allow to display frontend validation error when the field is not updated with backend error + this._changeDetector.detectChanges(); + } + isDetectChangesFromParent = true; })), ); @@ -69,6 +76,9 @@ export class SharedValidationDirective extends SharedAbstractDirective implement filter(s => this.isDifferent()), tap(validity => { this.updateErrorsMetadatas(validity); + setTimeout(() => { + isDetectChangesFromParent = false; + }, 1000); })), ); }