Can't figure out how to use this with Formik field component
See original GitHub issueI’m using Formik and trying to use this package, but Formik can’t see the value of the input and thus doesn’t validate or submit the form.
Here’s the PhonInputField component that I’m using …
import PhoneInput from "react-phone-number-input";
const PhoneInputField = ({
field,
form
}) => {
return (
<div className="input-field">
<PhoneInput
placeholder="Enter phone number"
name={field.name}
value={field.value}
onChange={field.onChange}
onBlur={field.onBlur}
/>
</div>
);
};
export default PhoneInputField;
And here’s how I’m using it in Formik …
<Formik
initialValues={initialValues}
validationSchema={signInSchema}
onSubmit={handleFormSubmit}
>
{({
isValid,
isSubmitting,
handleChange,
handleBlur
}) => (
<Form>
<Field
type="tel"
name="phone_number"
component={PhoneInputField}
/>
<div className="cta">
<button
type="submit"
disabled={!isValid || isSubmitting}
className="btn btn-primary big"
>Submit</button>
</div>
</Form>
)}
</Formik>
What am I doing wrong here?
Issue Analytics
- State:
- Created 4 years ago
- Comments:25 (10 by maintainers)
Top Results From Across the Web
<Field /> | Formik
Formik will automagically inject onChange , onBlur , name , and value props of the field designated by the name prop to the...
Read more >Formik Field not displaying entered value - Stack Overflow
This is the code snippet of my form, I have created a field and I want to change its value onChange. I don't...
Read more >A guide to React forms and events using Formik
The Field component in Formik is used to automatically set up React forms with Formik. It's able to get the value by using...
Read more >Formik Component in React - Pragim Tech
In rest of the cases, it is recommended to use Formik Component. One must remember that We cant use Form, field, Error Message...
Read more >Using Formik to Handle Forms in React - CSS-Tricks
The <Formik/> component exposes various other components that adds more abstraction and sensible defaults. For example, components like <Form/ > ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If it helps, here is my phoneinput/formik control
In case if anyone needs help this is my current implementation. Below approach works with both onChange and onBlur events and doesn’t throw error when string is given in field (disabled). Thanks to above replies: