Skip to content

Find existing errors in added validation group#333

Open
sarah-storm wants to merge 2 commits intomasterfrom
feature/update-to-avoid-duplicate-error-message
Open

Find existing errors in added validation group#333
sarah-storm wants to merge 2 commits intomasterfrom
feature/update-to-avoid-duplicate-error-message

Conversation

@sarah-storm
Copy link
Contributor

@sarah-storm sarah-storm commented Feb 24, 2026

Due to some new functionality around an 'add another' form type, there's a possibility that a form group could be added to the validator in a pre-existing errored state with a server error node.

The errored state is picked up if an input starts that way on page load (using the findErrors utility called by getInitialState) but it isn't also scanned for when a group is added by the API addGroup method.

I've added a call to the utility as part of the reducer - if thats the best place to do this?

[ACTIONS.ADD_GROUP]: (state, data) => Object.assign({}, state, {
groups: Object.assign({}, state.groups, data)
groups: Object.assign({}, state.groups, data),
errors: Object.assign({}, state.errors, findErrors(data))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Very strictly speaking findErrors could be lifted into addGroup, and the data argument passed to this reducer could be { groups, errors } to make the reducer a bit purer, but I don't think there's any practical benefit beyond functional purity! So, I'm approving it like this.

groups: Object.assign({}, state.groups, data),
errors: Object.assign({}, state.errors, findErrors(data))
}),
[ACTIONS.REMOVE_GROUP]: (state, groupName) => Object.assign({}, state, {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We might need to remove errors in removeGroup to clean up state at some point if we're using it for anything else, but not if you don't need it today!

@sarah-storm
Copy link
Contributor Author

Updates pushed! Thanks for the review - happy to make changes and get it clean and complete just now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants