[英]Popup closes byself when you try to type something at PhoneInput (React and React-phone-number-input)
TypeError: Cannot read properties of undefined (reading 'name')
and和
Uncaught TypeError: Cannot read properties of undefined (reading 'name')
I belive the problem is when the PhoneInput call function "OnChange" but I don't know how to fix it.我相信问题是当 PhoneInput 调用 function "OnChange" 但我不知道如何解决它。
Code src: landing-page/resources/js/components/contact-form/contact-form.jsx代码src:landing-page/resources/js/components/contact-form/contact-form.jsx
const inputs = [
..., {
id: "input-phone",
name: "phone",
type: "text",
errorMessage: "Por favor, preencha o seu testes",
pattern: "^[0-9]{2} [0-9]{4}-[0-9]{4}$",
label: "Celular",
},
const handleSubmit = (e) => {
e.preventDefault();
};
const onChange = (e) => {
setValues({ ...values, [e.target.name]: e.target.value });
console.log(values);
};
return(
<PhoneInput
key={item.id}
{...item}
international
withCountryCallingCode
countryCallingCodeEditable={false}
error={true}
defaultCountry="BR"
flags={flags}
flagUrl="https://flag.pk/flags/4x3/{xx}.svg"
value={values[item.name]}
onChange={onChange}
/>
);
The problem was solved.问题解决了。 I create a new function to call at "onChange".我创建了一个新的 function 来调用“onChange”。
const onPhoneChange = (phoneNumber) => {
setValues({ ...values, phone: phoneNumber });
}
and和
<PhoneInput
...
onChange={onPhoneChange};
/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.