diff --git a/src/move.js b/src/move.js index 6a481bf..32daaf7 100644 --- a/src/move.js +++ b/src/move.js @@ -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 } } diff --git a/src/move.test.js b/src/move.test.js index ea88d24..3b7afe5 100644 --- a/src/move.test.js +++ b/src/move.test.js @@ -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' }]