Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/insert.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { escapeRegexTokens } from './utils'
const insert: Mutator<any> = (
[name, index, value]: any[],
state: MutableState<any>,
{ changeValue }: Tools<any>
{ changeValue, resetFieldState }: Tools<any>
) => {
changeValue(state, name, (array: ?(any[])): any[] => {
const copy = [...(array || [])]
Expand All @@ -25,6 +25,10 @@ const insert: Mutator<any> = (
// Shift all higher indices up
const incrementedKey = `${name}[${fieldIndex + 1}]${tokens[2]}`
copyField(state.fields, key, newFields, incrementedKey)
if (fieldIndex === index) {
newFields[key] = state.fields[key]
resetFieldState(key)
}
return
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/insert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ describe('insert', () => {
touched: true,
error: 'A Error'
},
'foo[1]': {
error: 'B Error',
name: 'foo[1]',
touched: false,
lastFieldState: undefined
},
'foo[2]': {
name: 'foo[2]',
touched: true,
Expand Down Expand Up @@ -234,6 +240,11 @@ describe('insert', () => {
touched: true,
error: 'A Error'
},
'foo[0][1]': {
name: 'foo[0][1]',
touched: false,
error: 'B Error'
},
'foo[0][2]': {
name: 'foo[0][2]',
touched: true,
Expand Down
5 changes: 5 additions & 0 deletions src/unshift.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ describe('unshift', () => {
}
},
fields: {
'foo[0]': {
error: 'A Error',
name: 'foo[0]',
touched: false
},
'foo[1]': {
name: 'foo[1]',
touched: true,
Expand Down