issue: isDirty is updated to true only after entering the second digit #11049
Replies: 3 comments
-
I am also encountering this issue, this feel weird especially when use with select. The first select value change didn't make the form become dirty |
Beta Was this translation helpful? Give feedback.
-
Not sure if my explanation is the best, maybe/hopefully some other can contribute. You can then do console.log(fieldState.isDirty) inside onChange e.g
|
Beta Was this translation helpful? Give feedback.
-
One year later and this issue still persists... // This worked for me
const formIsDirty = form.formState.isDirty
const onSubmitModel = form.handleSubmit((templateData) => {
if (!formIsDirty) return next()
else return saveModel(templateData)
}
// This worked only on second keystroke
const onSubmitModel = form.handleSubmit((templateData) => {
if (!form.formState.isDirty) return next()
else return saveModel(templateData)
} |
Beta Was this translation helpful? Give feedback.
-
Version Number
7.47.0
Codesandbox/Expo snack
https://codesandbox.io/s/jolly-fast-74r8mf
Steps to reproduce
Maybe I'm just blind and can't find my error but the behavior seems a bit odd to me
bluebill1049
last week
Maintainer
Important: Make sure to provide all inputs' defaultValues at the useForm, so hook form can have a single source of truth to compare whether the form is dirty.
https://react-hook-form.com/docs/useform/formstate
this did not help and didn’t solve the issue. Since nobody answered, I have to create a new issue.
Expected behaviour
After the first digit is entered, isDirty should already be true.
In a larger component, the form also causes a re-render only after the first digit is entered. After that, it doesn't. It also causes a re-render when changing the date (not time) in one of the date pickers. Maybe this is related to that.
What browsers are you seeing the problem on?
Chrome, Safari
Relevant log output
No response
Code of Conduct
Beta Was this translation helpful? Give feedback.
All reactions