A numeric field can hold a string in formData while it is edited
Detect
- In your
onChangehandler, agetFormData()call or code reacting toliveValidateerrors: arithmetic or formatting on anumber/integerfield's value without atypeofcheck. - On the rendered page: typing
1.2.3or a lone-into a numeric field puts that string intoformData.
Change
asNumber() keeps the raw string when Number() can't parse it, so a half-typed 1.2.3 or a lone - stays in the field's slot while it is edited. RJSF's validation reports it as a type error, and the pattern blocks submitting it. Expect a string there:
-const onChange = ({ formData }: IChangeEvent<MyData>) => setTotal(formData.price * 2);
+const onChange = ({ formData }: IChangeEvent<MyData>) => {
+ if (typeof formData?.price === 'number') setTotal(formData.price * 2);
+};
A native number input, through ui:options.inputType: 'number' or the updown widget, reports an unparseable value as empty.
Verify
- Typing
-into the field doesn't break your handler, and the field shows RJSF's type error until the value parses.
Also read: