Skip to content

Commit

Permalink
Fixed moving of fields of different shapes (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikras authored Jul 13, 2019
1 parent ced46c6 commit de4a5ab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/move.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ const move: Mutator = (
state.fields[destKey] = {
...source,
name: destKey,
change: state.fields[destKey].change, // prevent functions from being overwritten
blur: state.fields[destKey].blur,
focus: state.fields[destKey].focus,
// prevent functions from being overwritten
// if the state.fields[destKey] does not exist, it will be created
// when that field gets registered, with its own change/blur/focus callbacks
change: state.fields[destKey] && state.fields[destKey].change,
blur: state.fields[destKey] && state.fields[destKey].blur,
focus: state.fields[destKey] && state.fields[destKey].focus,
lastFieldState: undefined // clearing lastFieldState forces renotification
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/move.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ describe('move', () => {
}
}
move(['foo', 0, 1], state, { changeValue })
expect(state).toEqual({
expect(state).toMatchObject({
formState: {
values: {
foo: [{ dog: 'banana dog' }, { dog: 'apple dog', cat: 'apple cat' }]
Expand Down

0 comments on commit de4a5ab

Please sign in to comment.