Replies: 11 comments 9 replies
-
Just to add some additional info, notice how with the "new" 7.22.5 behavior, the value1 Controlled component doesn't rerender, which leads to it's value not being set to undefined-across-versions.mp4I'd suggest to use |
Beta Was this translation helpful? Give feedback.
-
@Moshyfawn Using I was hoping this |
Beta Was this translation helpful? Give feedback.
-
Basically, this check is what's breaking your use-case. updateValue(
isUndefined(_name.current) ||
(isObject(fieldValues) && !objectHasFunction(fieldValues))
? { ...fieldValues }
: Array.isArray(fieldValues)
? [...fieldValues]
> : isUndefined(fieldValues)
> ? defaultValue
> : fieldValues,
); If the new value is |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I have the same problem CodeSandBox In |
Beta Was this translation helpful? Give feedback.
-
It's a text input, right? why not an empty string? |
Beta Was this translation helpful? Give feedback.
-
yes, I can set an empty string or null value to clear the text input, but I cannot clear the select record.mov |
Beta Was this translation helpful? Give feedback.
-
That's exactly what you're doing: clearing the field to it's default value which is You might wanna handle the onChange={(value) =>
if (!value) {
field.onChange(null)
}
} Or something along these lines |
Beta Was this translation helpful? Give feedback.
-
In my scenario, null is an alternative value. Is there any other solution apart from changing null to 0, converting it to null and submiting it to the backend? I don't want null to be this complicated. |
Beta Was this translation helpful? Give feedback.
-
Summary
|
Beta Was this translation helpful? Give feedback.
-
@bluebill1049 My issue with this change in the PR you linked is that it's a breaking change in a patch (0.0.1, not even 0.1.0). Going from If there are components like mine (of which I'm sure there are many) that support a list of values or In my case I could probably refactor a large part of my codebase to use |
Beta Was this translation helpful? Give feedback.
-
Version Number
Codesandbox/Expo snack
https://stackblitz.com/edit/react-hook-form-bug?file=Form.tsx
Steps to reproduce
I have created a component in the sandbox that replicates behaviour of the
Select
(dropdown) component that I have in my project. The idea is nothing new - you have a list of options in a dropdown, each of them has a value and you just pick one of them. Additionally, you can have an option at the top which indicates no selection (e.g. "All" or "None" depending on the context), whose value isundefined
instead of it being a string.As an example - it could be a list of colors to filter something by, e.g. "Red", "Blue", "Green" and one option above "All", which would indicate that no specific color should be used. That "All" option's value is
undefined
.To demonstrate the issue I'm having:
react-hook-form
library version is set to7.22.4
in the dependency panel on the left (important!). If it's not, paste[email protected]
into the package name field and press Enter.Form
component is being rendered with the following defaults in theindex.tsx
file (which are also reflected by the blue highlighted buttons in the panel on the right):7.22.5
by pasting[email protected]
into the package name field and pressing Enter.one
cannot be toggled toundefined
anymore yet the second option, whose default value wasundefined
can.I don't know what changed exactly between these two minor versions but this has broken all of my dropdown components as there is now no way of selecting the "All" options if the initial value of the form field was anything else but
undefined
.I tried a few versions post 7.22.5 and they all exhibit the same issue.
Expected behaviour
Form fields whose values can be 'undefined' should work the same way as they did prior to v7.22.5.
What browsers are you seeing the problem on?
Firefox, Chrome, Safari, Edge
Relevant log output
No response
Code of Conduct
Beta Was this translation helpful? Give feedback.
All reactions