我正在尝试以使用and的形式使用这个库 - https://github.com/react-native-datetimepicker/datetimepicker。我添加了一个验证以确保年龄至少为 18 岁(基于选择的日期)。Formik
yup
当我单击submit
按钮时,我收到错误 -Date of birth is required
这是我的代码片段
const [date, setDate] = useState(new Date());
const onChange = (event, selectedValue) => {
setDate(selectedValue);
};
const userProfileSchema = yup.object().shape({
dob: yup
.string()
.required("Date of birth is required")
.test('Date of Birth', 'Should be greather than 18', function(value) {
return moment().diff(moment(value), 'years') >= 18;
})
})
<Formik initialValues={{'dob': ''}}
onSubmit={handleSubmit}
validationSchema={userProfileSchema}
>
({handleChange, handleBlur, setFieldValue, handleSubmit, values, errors, }) => (
<DateTimePicker
testID="dateTimePicker"
value={date}
mode="date"
display="default"
onChange={onChange}
/>
)}
</Formik>
请问我在这里做错了什么?