diff --git a/src/app/shared/form/form.service.ts b/src/app/shared/form/form.service.ts index bb4a23f0d0..8a7eb184a8 100644 --- a/src/app/shared/form/form.service.ts +++ b/src/app/shared/form/form.service.ts @@ -108,11 +108,14 @@ export class FormService { }); } + /** + * Check if form group has an invalid form control + * @param formGroup The form group to check + */ public hasValidationErrors(formGroup: FormGroup | FormArray): boolean { let hasErrors = false; const fields: string[] = Object.keys(formGroup.controls); for (const field of fields) { - // Object.keys(formGroup.controls).forEach((field) => { const control = formGroup.get(field); if (control instanceof FormControl) { hasErrors = !control.valid && control.touched; @@ -122,7 +125,6 @@ export class FormService { if (hasErrors) { break; } - // }); } return hasErrors; } diff --git a/src/app/submission/edit/submission-edit.component.ts b/src/app/submission/edit/submission-edit.component.ts index bd9876da8e..c415b89b81 100644 --- a/src/app/submission/edit/submission-edit.component.ts +++ b/src/app/submission/edit/submission-edit.component.ts @@ -121,8 +121,8 @@ export class SubmissionEditComponent implements OnDestroy, OnInit { this.notificationsService.info(null, this.translate.get('submission.general.cannot_submit')); this.router.navigate(['/mydspace']); } else { - const { errors } = submissionObjectRD.payload; - this.submissionErrors = parseSectionErrors(errors); + const { errors } = submissionObjectRD.payload; + this.submissionErrors = parseSectionErrors(errors); this.submissionId = submissionObjectRD.payload.id.toString(); this.collectionId = (submissionObjectRD.payload.collection as Collection).id; this.selfUrl = submissionObjectRD.payload._links.self.href; diff --git a/src/app/submission/form/submission-form.component.ts b/src/app/submission/form/submission-form.component.ts index b04ce4914b..4cbffbca78 100644 --- a/src/app/submission/form/submission-form.component.ts +++ b/src/app/submission/form/submission-form.component.ts @@ -162,7 +162,6 @@ export class SubmissionFormComponent implements OnChanges, OnDestroy { this.uploadFilesOptions.authToken = this.authService.buildAuthHeader(); this.uploadFilesOptions.url = endpointURL.concat(`/${this.submissionId}`); this.definitionId = this.submissionDefinition.name; - // const { errors } = item; this.submissionService.dispatchInit( this.collectionId, this.submissionId, diff --git a/src/app/submission/objects/submission-objects.reducer.ts b/src/app/submission/objects/submission-objects.reducer.ts index 1b1b16b485..4159c56ae1 100644 --- a/src/app/submission/objects/submission-objects.reducer.ts +++ b/src/app/submission/objects/submission-objects.reducer.ts @@ -97,12 +97,12 @@ export interface SubmissionSectionObject { data: WorkspaceitemSectionDataType; /** - * The list of the section's errors to show + * The list of the section's errors to show. It contains the error list to display when section is not pristine */ errorsToShow: SubmissionSectionError[]; /** - * The list of the section's errors detected by the server + * The list of the section's errors detected by the server. They may not be shown yet if section is pristine */ serverValidationErrors: SubmissionSectionError[]; diff --git a/src/app/submission/sections/sections.service.ts b/src/app/submission/sections/sections.service.ts index 1ffcc2321c..dd68d42a87 100644 --- a/src/app/submission/sections/sections.service.ts +++ b/src/app/submission/sections/sections.service.ts @@ -173,6 +173,16 @@ export class SectionsService { ); } + /** + * Get the list of validation errors present in the given section + * + * @param submissionId + * The submission id + * @param sectionId + * The section id + * @param sectionType + * The type of section for which retrieve errors + */ getShownSectionErrors(submissionId: string, sectionId: string, sectionType: SectionsType): Observable { let errorsState$: Observable; if (sectionType !== SectionsType.SubmissionForm) { @@ -422,9 +432,11 @@ export class SectionsService { * @param data * The section data * @param errorsToShow - * the list of the section's errors to show + * The list of the section's errors to show. It contains the error list + * to display when section is not pristine * @param serverValidationErrors - * the list of the section errors detected by the server + * The list of the section's errors detected by the server. + * They may not be shown yet if section is pristine * @param metadata * The section metadata */