form icon indicating copy to clipboard operation
form copied to clipboard

Array setFieldValue not behaving as expected.

Open zthng opened this issue 1 year ago • 0 comments

Hello,

I understand that this function attempts to update the keys in place if they are defined by the incoming updated value. However, this kind of breaks setFieldValue in my opinion, where we need to override an entry in the array with the exact value required.

For example, if I had the shape as { a: string, b?: string, c?; string } and I do form.setFieldValue('myArray', 0, { a: '123' }); I expected the first item in form.state.values.myArray to be exactly { a: '123' } rather than { a: '123', b: 'previousBValue', c: 'previousCValue' }

Particularly, lines 57-60. https://github.com/TanStack/form/blob/2bebfd5214c4cdfbf6feacb7b1e25a6825957062/packages/form-core/src/utils.ts#L42-L79

Is this an intentional use case? How do I unset the values of b and c in this situation then?

Haha also, please do put me in my place if I misunderstood anything. 🙏🏻

zthng avatar Jul 17 '24 02:07 zthng