New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected fields values with useFieldArray when setting defaultValues #924
Comments
I think a lot of people having this concern and question: #919 i will update the website soon, i think you are expecting the form to be controlled, but indeed it's not, watch() API is not same as state, watch is for watching input change after input rendered. |
Ah ok, I only included |
I will do that tonight :) |
I may have a work around, will try out tonight |
Digging into this a little bit, it looks like the issue stems from For consistency's sake, would it make more sense to keep the shape of Example: // Before
export const appendId = <
FormArrayValues extends {
id?: string;
} & FieldValues = FieldValues
>(
value: FormArrayValues,
) => ({
...value, // <-- Change this guy
id: generateId(),
});
// After
export const appendId = <
FormArrayValues extends {
id?: string;
} & FieldValues = FieldValues
>(
value: FormArrayValues,
) => ({
value, // <-- To this
id: generateId(),
}); |
some good progress @ryanwalters try this CSB: https://codesandbox.io/s/bold-sound-7lej4 |
* #924 experience imporvement over watch with field array * working in progress * fix empty value situation * improve type * update unit tests * adding unit test coverage * include more unit tests for useFieldArray * convert fill empty array into function * change to more efficient array method * improve unit test and fix errors and touched fields shuffle
|
I'll give it a look at some point today. Thanks for the speedy turnaround! Edit: I think there was a miscommunication somewhere. I see you updated the title of this issue, but my issue wasn't with watch, it was with the value that Please see the output of my codesandbox and my comment above with a possible fix. I can also create a PR if that's easier. |
oh sure PR welcome @ryanwalters |
yes we only support |
sorry for not reading your issue carefully... that was my bad. yes, right now we don't only support object due to the nature of uncontrolled inputs which required unique id during mapping. I will update documentation accordingly. apologize for not reading your issue carefully, I get overwhelmed by issue around watch() and assume the issue was the same. |
Are you open to supporting strings and arrays as well as objects? It seems like a useful feature to me (obviously 😄). We can probably work out an API that is not a breaking change. The change I proposed above would be a breaking change, but seems cleaner to me. A non-breaking solution would be to set a |
hey @ryanwalters I guess it's tradeoff with FieldArray uncontrolled, because it will need to be an object which contains a unique ID for the |
…ues, assign other values (e.g. strings, arrays) to value property
Opened #940. The solution should be backwards compatible, and keeps the unique id. |
thanks, i added some feedback take a look there :) |
Hey guys, I'm still seeing issues here (on 4.8.0), whereby the array doesn't stay intact when calling
Illustrated in this sandbox by stringifying Sorry if this is an unrelated issue (or if I'm not using Thanks in advance for your continuoued efforts on this component, it's much appreciated. |
hey @blakecannell i think you want to use watch() instead getValues(). |
I am having the same issue, still no support for string. I kind of found a work around
|
Describe the bug
I'm not 100% sure that this is a bug, but I know that what is happening is not what I expected.
When setting
defaultValues
on an array withuseForm
, I would expect the resultfields
array usinguseFieldArray
to contain those values as-is rather than becoming mangled.Example:
This issue then snowballs into other issues when trying to display, append, delete, etc the values of the fields, but I figured I'd start here and step through the other issues only if needed.
To Reproduce
Steps to reproduce the behavior:
Codesandbox link
https://codesandbox.io/s/upbeat-bose-pt26m
Expected behavior
See
Expected output
in the code snippet above.Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: