UoE/fix: prevent multi-value form fields from losing input and 'Add more'#3
Open
milanmajchrak wants to merge 2 commits intodatashare-UoEMainLibrary-dspace-8_xfrom
Open
Conversation
… button when last item is removed
There was a problem hiding this comment.
Pull request overview
This PR updates the shared dynamic form component’s array-item removal behavior to avoid fully removing the final remaining entry in a repeatable field, which helps preserve the UI state (e.g., “Add more”) and prevents losing user input unexpectedly.
Changes:
- Update
FormComponent.removeItemto clear the last remaining array entry instead of removing it. - Expand
FormComponentspecs to reflect the new “clear last item” behavior and adjust prior removal tests to remove a non-last item. - Rename the Datashare submission service spec to match the actual service class name.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/app/shared/form/form.component.ts |
Changes array item removal logic to clear the final entry rather than removing it. |
src/app/shared/form/form.component.spec.ts |
Updates/remaps existing array-removal tests and adds new tests for “last item is cleared” behavior. |
src/app/datashare/datashare-submission.service.spec.ts |
Fixes spec naming/injection to use DatashareSubmissionService. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In submission metadata form, multi-value fields (e.g. Type, Funder, Data Creator)
have an "Add more" button to add additional rows. When a user rapidly removed
all rows, the "Add more" button disappeared entirely, making it impossible
to add new values without reloading the page.
Root cause
The
removeItem()method inform.component.tsunconditionally calledremoveFormArrayGroup()for every removal — including the last remaining item.When the last item was removed, the underlying
FormArraybecame empty,Angular destroyed the array's DOM container, and the "Add more" button
(rendered inside the array template) was destroyed along with it.
Fix
Ported the upstream DSpace fix pattern: when the user removes the last
remaining item (index 0, array length 1), the method now clears its value
instead of removing the row. This keeps the
FormArrayat length >= 1,preserving the DOM container and the "Add more" button.
Origin of fix
Adapted from the upstream DSpace Angular
mainbranch approach. The patternensures multi-value form arrays never reach length 0.
Changed files
src/app/shared/form/form.component.tssrc/app/shared/form/form.component.spec.tssrc/app/datashare/datashare-submission.service.spec.tsDatashareCustomisedSubmissionService→DatashareSubmissionService)Video of fixed feature:
fix-addmore-button-persists.webm