简体   繁体   中英

isDirty issue with react hook form and react number format

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM