Why input request type string?
I use OutlinedInput, receive it as a number and submit. At this time, the amount is delivered as a string, not a number.
2 Replies
Hi @florent. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
The issue you're experiencing is related to how form libraries, like
react-hook-form
(which is used by Refine), handle number inputs. By default, HTML form inputs of type "number" still return their values as strings. This is because the HTML DOM API treats input values as strings by default.
In your case, even though you've specified the input type as "number", the value is still being returned as a string. This is standard behavior and not a bug.
To get around this, you can use the valueAsNumber
property when registering the input field with react-hook-form
. This tells react-hook-form
to treat the input value as a number, not a string.
Here's how you can modify your code:
This issue was discussed in a Github issue (https://github.com/refinedev/refine/issues/3550) related to the Refine project. The solution provided there should apply to your case as well.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1184365192482652173> kapa.ai is still learning and improving, please let us know how it did by reacting below