我正在使用Formik并尝试使用这个包,但是Formik看不到输入的值,因此不会验证或提交表单。
这是我正在使用的PhonInputField组件...
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;下面是我如何在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>我在这里做错了什么?
===
我试着在这个项目的Github回购页面上问这个问题,但没有成功。
我也试着这样做...
<PhoneInput
placeholder="Enter phone number"
name={field.name}
value={field.value}
onChange={value => field.onChange({ value })}
onBlur={value => field.onBlur({ value })}
/>但是,Formik仍然看不到字段值。
发布于 2019-11-23 16:46:55
对于那些可能遇到这个问题的人,在这里的Github回购页面中已经回答了这个问题。
https://github.com/catamphetamine/react-phone-number-input/issues/298#issuecomment-557746103
发布于 2020-03-10 12:17:38
onChange={(phone, country) =>
setValues({
...values,
phone: phone,
countryCode: country.countryCode
})
}https://stackoverflow.com/questions/58979846
复制相似问题