Replies: 37 comments 39 replies
-
Should be working properly. See this CSB
|
Beta Was this translation helpful? Give feedback.
-
Hmm. If I initialize all fields with Isn't this a bit odd? |
Beta Was this translation helpful? Give feedback.
-
So, talking in #7590, it seems like the only correct way to have controlled input fields properly reset is to set their default value as a string. |
Beta Was this translation helpful? Give feedback.
-
It worked for me as well with the controller component |
Beta Was this translation helpful? Give feedback.
-
Im still struggling with this. I initialise my form with the following. Bear in mind there are other fields in
But calls to reset, even with passing in the original defaultValues, have no effect. How can I get it to reset without having to pass in an empty string for every field? |
Beta Was this translation helpful? Give feedback.
-
I have the same problem, I understand that I can reset all field, giving theme a default value like an empty string, but I don't really want to do that, otherwise the validation logic (zod) won't show required, but something like you passed a string where a number is required. I have also tried to set all values to undefined instead calling reset, but while internally the value is set to undefined, the ui is not updated. |
Beta Was this translation helpful? Give feedback.
-
Same problem here, if i specify |
Beta Was this translation helpful? Give feedback.
-
In my case the form state still remains even though setting reset(initialPayload, { keepIsSubmitted: false, keepSubmitCount: false }); |
Beta Was this translation helpful? Give feedback.
-
Also having trouble with this ... The only way to reset the form right now is to use
|
Beta Was this translation helpful? Give feedback.
-
Has the same issue. This but happens after the 7.22.0 version downgrading works to me. @bluebill1049 |
Beta Was this translation helpful? Give feedback.
-
any update on this, facing issue on |
Beta Was this translation helpful? Give feedback.
-
Same issue here. |
Beta Was this translation helpful? Give feedback.
-
I have found a workaround for this.
For some reason |
Beta Was this translation helpful? Give feedback.
-
Same issue here, really annoying. I have to reset each field manually in a dirty way (using zod validation) form.reset({
field1: null as any,
field2: null as any
...
}) |
Beta Was this translation helpful? Give feedback.
-
Any updates on a fix here? Resetting by setting every key to null works but is annoying to do all the time especially for dynamic forms. |
Beta Was this translation helpful? Give feedback.
-
I encountered the same problem and realized there was an issue with my Your TextInput: const TextInput = forwardRef<RNTextInput, Props>((props: Props, ref) => {
return (
<RNTextInput
ref={ref}
{...props}
/>
</>
);
}); Your controller: const TextInputController = (inputProps: TextInputProps) => {
const {
field,
formState: { errors }
} = useController({
name: inputProps.FieldName
});
return (
<TextInput
onChangeText={field.onChange}
{...field}
{...inputProps}
/>
);
}; Eventually, you can reset your form by: const { reset } = useForm({
defaultValues: {something: ""},
});
reset() |
Beta Was this translation helpful? Give feedback.
-
I honestly don't get why this form package is so popular.
I get the concerns around performance, fewer re-renders and updates but if the formState is not properly updated and reset, then this package is not a working solution for forms. Better have a package that works than having good performance but not working... Sorry for venting, not happy using this. EDIT: TanStack Form is now available |
Beta Was this translation helpful? Give feedback.
-
For me using |
Beta Was this translation helpful? Give feedback.
-
Created this issue: #11751 |
Beta Was this translation helpful? Give feedback.
-
Still experience this as an issue. |
Beta Was this translation helpful? Give feedback.
-
For me that worked was to pass to e.g.
|
Beta Was this translation helpful? Give feedback.
-
Really don't understand why this is hard to implement, and it seems like it should be a core part of the library. If I call a method called reset, I want my form to go back to its default, initial state. Even if I pass in my default object to the reset method, it still maintains existing values for things I don't explicitly set to null! Even setting For now, to support my use case of dynamic forms, I am doing this to make sure it gets reset properly: const existingValueReset = form.getValues();
for (let key of Object.keys(existingValueReset)) {
existingValueReset[key] = null;
}
reset({ ...existingValueReset, ...defaultValues }); Another option would be to use the callback of reset: reset((prev) => {
Object.keys(prev).forEach((key) => prev[key] = null);
return {...prev, ...defaultValues};
}); |
Beta Was this translation helpful? Give feedback.
-
I found a solution for myself. "react-hook-form": "^7.46.1"
|
Beta Was this translation helpful? Give feedback.
-
I am loading the default form values from server side and when the response comes back, It's very inconvenience to do so with current implementation. |
Beta Was this translation helpful? Give feedback.
-
Without handlying events by yourself:
You can do further clearing operations by adding an onClickHandler. But the basic input element only get cleared if you set the type to reset, of the reset button. |
Beta Was this translation helpful? Give feedback.
-
This worked for me: let defaultValues const { useEffect(() => { const handleClose = () => { |
Beta Was this translation helpful? Give feedback.
-
I had this issue with an array of objects not resetting when opening in a dialog. My fix for now.
|
Beta Was this translation helpful? Give feedback.
-
It seemed like the formState wasn't being reflected internally, |
Beta Was this translation helpful? Give feedback.
-
Here, another solution:
function onSubmit(data) {
try {
console.log("Form Submitted!");
console.log(data);
} catch (error) {
console.log("errors: ", error);
} finally {
reset();
}
}
|
Beta Was this translation helpful? Give feedback.
-
I was having a problem redefining the appearance of the input select, what solved it for me was passing the file.value to the Select value and it needs to have a defaultValue defined. |
Beta Was this translation helpful? Give feedback.
-
I'm trying to clear my form, but only succeed half the way.
The stored values in RHF is cleared, but the values in my input components are still there.
I have also tried with keepValues: false
If I explicitly set the values to null, the actual input fields gets cleared.
My fields are controlled. I have connected
onChange
,value
andref
. Everything works as it should in the form, butreset
mis-behaves or is mis-used by me.Beta Was this translation helpful? Give feedback.
All reactions