我们可以在我下面提到的 formik YupValidationSchema 中添加自定义验证吗?
YupValidationSchema = () => {
return Yup.object({
Email: Yup.string()
.max(256, "Length exceed 256 chars")
.matches(EMAIL_REGEXP, "Enter a valid email address")
.required("Email is required")
})
}
Run Code Online (Sandbox Code Playgroud)
我需要为电子邮件字段添加一项验证,就像它应该接受某些域一样
let domainVal = companyName.some((val) => email.includes(val));
if(!domainVal) error('Invalid')
else success('Valid');
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我如何在 yupvalidationschema 中添加此域验证代码吗?
下面是我尝试从下拉列表中选择值的代码。 handleChange不起作用,当我从下拉列表中选择值时,它不会使用下拉列表中选定的值进行更新。它正在消失(空白)。
当我选择它时,下拉值会被填充,它不会捕获新的选定值。
有人可以帮助我解决这个问题吗?就像我在这里缺少的一样?
export const FormikSelectField = ({ label, ...props }) => {
const [field, meta] = useField(props);
const [isFocused, setOnFocus] = useState(false);
const handleChange = (value) => {
// this is going to call setFieldValue and manually update values.topcis
console.log('Value in handlechange..', value ,'and', props.name);
props.onChange(props.name, value.value);
};
const handleFocus = () => {
setOnFocus(true);
};
const handleBlur = (e) => {
// this is going to call setFieldTouched and manually update touched.topcis
setOnFocus(false);
props.onBlur(props.name, true);
field.onBlur(e); …Run Code Online (Sandbox Code Playgroud)