Skip to content

Commit 6aa0722

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

File tree

2 files changed

+3
-151
lines changed

2 files changed

+3
-151
lines changed

src/remove.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,12 @@ const remove: Mutator<any> = (
2727
if (fieldIndex === index) {
2828
// delete any subfields for this array item
2929
delete state.fields[key]
30-
3130
// delete any submitErrors for this array item
32-
// if root key of array item and has submitErrors
31+
// if the root key of the delete index
3332
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}`
33+
const path = `formState.submitErrors.${name}`
4134
const submitErrors = getIn(state, path)
42-
// if has submitErrors
35+
// if has submitErrors for array
4336
if (Array.isArray(submitErrors)) {
4437
submitErrors.splice(index, 1)
4538
state = setIn(state, path, submitErrors)

src/remove.test.js

Lines changed: 0 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -498,145 +498,4 @@ describe('remove', () => {
498498
foo: [{ key: 'B Submit Error' }]
499499
})
500500
})
501-
502-
it('should remove value from the specified index with submitError if one error in array (root is an array)', () => {
503-
const array = ['a', { key: 'val' }]
504-
const changeValue = jest.fn()
505-
const renameField = jest.fn()
506-
function blur0() {}
507-
function change0() {}
508-
function focus0() {}
509-
function blur1() {}
510-
function change1() {}
511-
function focus1() {}
512-
function blur2() {}
513-
function change2() {}
514-
function focus2() {}
515-
const state = {
516-
formState: {
517-
values: array,
518-
submitErrors: [
519-
{
520-
key: 'A Submit Error'
521-
}
522-
]
523-
},
524-
fields: {
525-
'[0]': {
526-
name: '[0]',
527-
blur: blur0,
528-
change: change0,
529-
focus: focus0,
530-
touched: true,
531-
error: 'A Error'
532-
},
533-
'[0].key': {
534-
name: '[0].key',
535-
blur: blur2,
536-
change: change2,
537-
focus: focus2,
538-
touched: false,
539-
error: 'A Error'
540-
},
541-
'[1]': {
542-
name: '[1]',
543-
blur: blur1,
544-
change: change1,
545-
focus: focus1,
546-
touched: false,
547-
error: 'B Error'
548-
},
549-
'[1].key': {
550-
name: '[1].key',
551-
blur: blur2,
552-
change: change2,
553-
focus: focus2,
554-
touched: false,
555-
error: 'B Error'
556-
}
557-
}
558-
}
559-
560-
const returnValue = remove(['', 0], state, {
561-
renameField,
562-
changeValue,
563-
getIn,
564-
setIn
565-
})
566-
expect(returnValue).toBeUndefined()
567-
expect(getIn(state, 'formState.submitErrors')).toEqual([])
568-
})
569-
570-
it('should remove value from the specified index with submitError if two errors in array (root is an array)', () => {
571-
const array = ['a', { key: 'val' }]
572-
const changeValue = jest.fn()
573-
const renameField = jest.fn()
574-
function blur0() {}
575-
function change0() {}
576-
function focus0() {}
577-
function blur1() {}
578-
function change1() {}
579-
function focus1() {}
580-
function blur2() {}
581-
function change2() {}
582-
function focus2() {}
583-
const state = {
584-
formState: {
585-
values: array,
586-
submitErrors: [
587-
{
588-
key: 'A Submit Error'
589-
},
590-
{
591-
key: 'B Submit Error'
592-
}
593-
]
594-
},
595-
fields: {
596-
'[0]': {
597-
name: '[0]',
598-
blur: blur0,
599-
change: change0,
600-
focus: focus0,
601-
touched: true,
602-
error: 'A Error'
603-
},
604-
'[0].key': {
605-
name: '[0].key',
606-
blur: blur2,
607-
change: change2,
608-
focus: focus2,
609-
touched: false,
610-
error: 'A Error'
611-
},
612-
'[1]': {
613-
name: '[1]',
614-
blur: blur1,
615-
change: change1,
616-
focus: focus1,
617-
touched: false,
618-
error: 'B Error'
619-
},
620-
'[1].key': {
621-
name: '[1].key',
622-
blur: blur2,
623-
change: change2,
624-
focus: focus2,
625-
touched: false,
626-
error: 'B Error'
627-
}
628-
}
629-
}
630-
631-
const returnValue = remove(['', 0], state, {
632-
renameField,
633-
changeValue,
634-
getIn,
635-
setIn
636-
})
637-
expect(returnValue).toBeUndefined()
638-
expect(getIn(state, 'formState.submitErrors')).toEqual([
639-
{ key: 'B Submit Error' }
640-
])
641-
})
642501
})

0 commit comments

Comments
 (0)