Skip to content

Commit 74fbfc0

Browse files
author
Vitaliy Parkhomenko
committed
fix(remove): submit errors are not removed on "fields.remove" call
1 parent 36bff53 commit 74fbfc0

File tree

4 files changed

+338
-13
lines changed

4 files changed

+338
-13
lines changed

src/remove.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { escapeRegexTokens } from './utils'
66
const remove: Mutator<any> = (
77
[name, index]: any[],
88
state: MutableState<any>,
9-
{ changeValue, renameField }: Tools<any>
9+
{ changeValue, renameField, getIn, setIn }: Tools<any>
1010
) => {
1111
let returnValue
1212
changeValue(state, name, (array: ?(any[])): any[] => {
@@ -27,6 +27,24 @@ const remove: Mutator<any> = (
2727
if (fieldIndex === index) {
2828
// delete any subfields for this array item
2929
delete state.fields[key]
30+
31+
// delete any submitErrors for this array item
32+
// if root key of array item and has submitErrors
33+
if (key === `${name}[${index}]`) {
34+
// do it only for removable index
35+
// Can array be in root?
36+
// formState.submitErrors[]
37+
// formState.submitErrors.pathToArray[]
38+
const path = name
39+
? `formState.submitErrors.${name}`
40+
: `formState.submitErrors${name}`
41+
const submitErrors = getIn(state, path)
42+
// if has submitErrors
43+
if (Array.isArray(submitErrors)) {
44+
submitErrors.splice(index, 1)
45+
state = setIn(state, path, submitErrors)
46+
}
47+
}
3048
} else if (fieldIndex > index) {
3149
// shift all higher ones down
3250
delete state.fields[key]

0 commit comments

Comments
 (0)