Reputation: 1481
Using Formik, how do I change the value of the input when the onBlur event occurs?
I have a Formik form with an input for phone number, and I want to format the phone number when the input blurs.
Upvotes: 2
Views: 6317
Reputation: 1481
This solved it for me:
<Formik
render={props => (
<Form>
<Field
name="phone"
component={CustomInputComponent}
onBlur={event => {
const formatted = formatPhoneNumber(props.values['phone']);
props.setFieldValue('phone', formatted);
props.handleBlur(event);
}}
/>
</Form>
)}
/>
Upvotes: 3