-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't figure out how to use this with Formik field component #298
Comments
Perhaps the reason could be |
Well, then it requires a properly constructed event it seems. |
Or maybe not, maybe it's something else. |
When I do it like this the warnings go away, but still can't seem to detect that the field has a value and thus won't activate the "submit" button ...
|
You'll have to ask |
OK, thank you for your effort, I'll try to post this on StackOverflow, and maybe someone who faced this before can give his insight. |
There has also been a previous thread on Formik: |
If it helps, here is my phoneinput/formik control
|
@AndrewStratigos That did actually work, Thanks a lot man.
Again, thanks a bunch 👍 |
@Shaker-Hamdi. I'm still struggling to make this work for me. Can you take a look at my sandbox and see? |
I may be late to the party but for anyone else here having issues with their onChange handler, remember this also comes with a curried option, in a regular web input formik can take the name attribute from the target it receives in the change handler, React-native generally doesn't provide a synthetic event (it does but its different) most people tend to use the instead of calling the change (or blur) handlers like we do on web: you call it with the attribute name: |
@jdmg94 So what does the ultimate Formik component look like then? import React, { useCallback } from 'react'
import PropTypes from 'prop-types'
import PhoneInput from 'react-phone-number-input`
function FormikPhoneInput(ref, { name, onChange, formik, ...rest }) {
const onChange_ = useCallback(value => onChange(value || ''), [onChange])
return (
<PhoneInput
{...rest}
ref={ref}
name={name}
onChange={onChange_}/>
)
}
FormikPhoneInput = React.forwardRef(FormikPhoneInput)
FormikPhoneInput.propTypes = {
name: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
formik: PropTypes.shape({
handleChange: PropTypes.func.isRequired,
handleBlur: PropTypes.func.isRequired
}).isRequired
}
export default FormikPhoneInput Also, in v3.x of this library, |
remove |
@catamphetamine please find a working implementation for future reference. |
I have modified @AndrewStratigos 's version. This version works right with Formik's onBlur, allowing you to validate the field on blur.
|
@boriswinner Ok, what are the main issues when using this library with
Perhaps we could add a section in the readme on using this library with |
That's how it currently is.
What? Not clear what you meant there. |
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:
|
This works fine for me,
|
@ackalhan I've updated the README with a |
What do we need to pass in |
What do we need to pass in the |
Thanks a lot MidhaTahir Now I have finally passed the issue from react-phone-input-2😊😊 |
Thank you so much. This helped me. Apparently, the trick was the |
I'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 ...
And here's how I'm using it in Formik ...
What am I doing wrong here?
The text was updated successfully, but these errors were encountered: