How do I integrate react-number-format into react-hook-form with the Material UI text field? #2200
-
I can't think of any way to integrate it.Have you or have you seen examples of such integrations. Like on Codesandbox.io or something? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 23 replies
-
Take a look at the example: https://codesandbox.io/s/react-hook-form-v6-controller-qsd8r there is a mask component should be quite similar. |
Beta Was this translation helpful? Give feedback.
-
Here is an example of react-number-format + react-hook-form + Material UI |
Beta Was this translation helpful? Give feedback.
-
This worked for me and had it under hook form's state provider: <Controller
render={({ onChange, value }) => (
<NumberFormat
allowNegative={false}
decimalScale="2"
onValueChange={(v) => onChange(v.value)}
prefix="$"
value={value}
/>
)}
name={name}
control={control}
fixedDecimalScale
/> The key is wiring up the |
Beta Was this translation helpful? Give feedback.
-
Hi @bluebill1049
My controller code:
|
Beta Was this translation helpful? Give feedback.
-
I can get the input field state, but validation only works for empty fields despite character length checks. What could be the issue here? @bluebill1049 Yup Schema
Controller
|
Beta Was this translation helpful? Give feedback.
Here is an example of react-number-format + react-hook-form + Material UI
https://codesandbox.io/s/late-feather-shr01