Skip to content

Resolve field instance models using index when filtering errors#4434

Merged
tdonohue merged 1 commit intoDSpace:mainfrom
the-library-code:fix_repeated_field_errors
Jun 12, 2025
Merged

Resolve field instance models using index when filtering errors#4434
tdonohue merged 1 commit intoDSpace:mainfrom
the-library-code:fix_repeated_field_errors

Conversation

@kshepherd
Copy link
Member

Description

This is a very small change that fixes form error handling for repeated fields, by correctly passing the field index to formBuilderService.findById() when resolving a parsed field to a dynamic form control model.

Without this change applied, the error is always rendered for the first element only, and in some cases does not correctly invalidate or render an error message at all.

With this change applied, the correct field instance is made invalid and the message displayed.

This might not be noticeable to many DSpace configurations since most errors are "required" errors, where by definition a repeated field is usually not empty/null, but you can test this with a custom error message, or the regex submission config validator.

Instructions for Reviewers

To test:

  • Set up a repeatable onebox field (e.g. subject keyword) and give it a regex validation rule in submission-forms.xml
  • Add several valid instances of the field that will match the regex. Save.
  • Add an invalid instance, or change another instance to not match the regex. Save.

Without this PR applied, the error will either not display or display only for index 0.

With this PR applied, the error should display properly in the correct field index.

Checklist

  • My PR is created against the main branch of code (unless it is a backport or is fixing an issue specific to an older branch).
  • My PR is small in size (e.g. less than 1,000 lines of code, not including comments & specs/tests), or I have provided reasons as to why that's not possible.
  • My PR passes ESLint validation using npm run lint
  • My PR passes all specs/tests and includes new/updated specs or tests based on the Code Testing Guide.
  • My PR includes details on how to test it. I've provided clear instructions to reviewers on how to successfully test this fix or feature.

@kshepherd kshepherd self-assigned this Jun 4, 2025
@kshepherd kshepherd added bug quick win Pull request is small in size & should be easy to review and/or merge 1 APPROVAL pull request only requires a single approval to merge port to dspace-8_x This PR needs to be ported to `dspace-8_x` branch for next bug-fix release port to dspace-9_x This PR needs to be ported to `dspace-9_x` branch for next bug-fix release labels Jun 4, 2025
@tdonohue tdonohue moved this to 🙋 Needs Reviewers Assigned in DSpace 10.0 Release Jun 4, 2025
@pcg-kk pcg-kk self-requested a review June 9, 2025 10:52
pcg-kk
pcg-kk approved these changes Jun 11, 2025
Copy link
Contributor

@pcg-kk pcg-kk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look fine for me - error not happen anymore

@michdyk michdyk moved this from 🙋 Needs Reviewers Assigned to 👍 Reviewer Approved in DSpace 10.0 Release Jun 12, 2025
@tdonohue
Copy link
Member

@kshepherd : from looking at form.component.ts on dspace-7_x, it looks like this might impact that release as well. The code at least looks the same. Do you agree?

@kshepherd kshepherd added the port to dspace-7_x This PR needs to be ported to `dspace-7_x` branch for next bug-fix release label Jun 12, 2025
@kshepherd
Copy link
Member Author

@tdonohue agreed! i added the label, thanks

@tdonohue tdonohue added this to the 10.0 milestone Jun 12, 2025
Copy link
Member

@tdonohue tdonohue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Code makes sense to me. Thanks @kshepherd !

@tdonohue tdonohue merged commit 7c27392 into DSpace:main Jun 12, 2025
15 checks passed
@github-project-automation github-project-automation bot moved this from 👍 Reviewer Approved to ✅ Done in DSpace 10.0 Release Jun 12, 2025
@dspace-bot
Copy link
Contributor

Successfully created backport PR for dspace-7_x:

@dspace-bot
Copy link
Contributor

Successfully created backport PR for dspace-8_x:

@dspace-bot
Copy link
Contributor

Successfully created backport PR for dspace-9_x:

@tdonohue tdonohue removed port to dspace-7_x This PR needs to be ported to `dspace-7_x` branch for next bug-fix release port to dspace-8_x This PR needs to be ported to `dspace-8_x` branch for next bug-fix release port to dspace-9_x This PR needs to be ported to `dspace-9_x` branch for next bug-fix release labels Jun 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1 APPROVAL pull request only requires a single approval to merge bug quick win Pull request is small in size & should be easy to review and/or merge

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

4 participants