I'm using react-number-format
with react-hook-form
Controller
for a currency input.
The formState
does not update correctly: isDirty
and dirtyFields
do not seem to update when editing the masked number input and then deleting the text.
I set the defaultValues
to ''
(empty string).
If I input a number, I can see that isDirty
is true. But if I delete the input, and the value is ''
(empty string) I still see isDirty
is true - but the value is exactly the same as the defaultValue.
The issue is with line 54 in the file masked-hook-form-inputs.js
:
onChange(values.floatValue);
the value of floatValue
can be undefined
, and this caused the problem.
The solutionn Change line 54 to onChange(isNaN(values.floatValue)? '': values.floatValue);
Note that it's better to use ''
(empty string) and not null
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.