Skip to content

Commit 0b40afc

Browse files
committed
LIBDRUM-909. Fix race condition in validation error display after deposit
When depositing with missing required fields, the backend returns errors that trigger a form re-initialization via hasMetadataEnrichment(). This causes checksForErrors() to be called multiple times concurrently. The first call correctly marks form controls as touched, but initForm() then rebuilds the controls, wiping their touched state. The second call is skipped by the isEqual() guard in checkSectionErrors() because this.sectionData.errorsToShow was already updated by the first call, so markAsTouched() is never re-applied to the rebuilt controls. This fix resets this.sectionData.errorsToShow to [] before calling initForm() in the hasMetadataEnrichment branch of updateForm(), so the second checksForErrors() call treats the errors as new and re-applies them to the rebuilt form controls. Co-authored-by: Perplexity AI <noreply@perplexity.ai> https://umd-dit.atlassian.net/browse/LIBDRUM-909
1 parent 5388c7b commit 0b40afc

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

docs/DrumAngularCustomizations.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,22 @@ would successfully complete:
8080

8181
* Commented out the "codecov" job, because UMD does not have an appropriate key
8282
for uploading the results to codecov.io.
83+
84+
## Change to Submission Form Validation Handling
85+
86+
The "updateForm" method in the "SubmissionSectionFormComponent" class
87+
(src/app/submission/sections/form/section-form.component.ts) has been
88+
modified to clear the form validation errors held by Angular when
89+
receiving a form update from the back-end.
90+
91+
This change is intended to fix an issue (see LIBDRUM-909) in which submitting
92+
a form without all the required fields populated would only show a brief
93+
"flash" of the validation errors, and then not show GUI validation
94+
warnings on all affected fields. This is apparently caused by a race condition
95+
between the Angular validation handling, and a page refresh triggered by the
96+
DSpace backend response.
97+
98+
It is unclear whether this is the optimal fix, so it has not been submitted
99+
upstream to DSpace. Also, DSpace has been working on various similar fixes, so
100+
the changes in this class should be re-evaluated on upgrades, and
101+
removed if possible.

src/app/submission/sections/form/section-form.component.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,20 @@ export class SubmissionSectionFormComponent extends SectionModelComponent {
370370
this.isUpdating = true;
371371
this.formModel = null;
372372
this.cdr.detectChanges();
373+
// UMD Customization
374+
// Clear errors before calling initForm.
375+
// This is needed because this code path may be called multiple times,
376+
// and checksForErrors does a no-op (essentially clearing the
377+
// validation errors) if the "this.sectionData.errorsToShow" hasn't
378+
// changed.
379+
// Clearing the "errorsToShow" ensures that checkForErrors actually
380+
// shows the errors, no matter how many times this code block is called.
381+
//
382+
// Note: Future DSpace changes may eliminate the need for this change,
383+
// so it should be checked when doing DSpace upgrades, and removed,
384+
// if possible.
385+
this.sectionData.errorsToShow = [];
386+
// End UMD Customization
373387
this.initForm(sectionData, errors, sectionState.serverValidationErrors);
374388
this.checksForErrors(errors);
375389
this.isUpdating = false;

0 commit comments

Comments
 (0)