Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

How to validate interdependent strings using yup in react native

$
0
0

I have two strings of date start_date and end_date. Below have empty string as there initial value:

export interface FilterSchema {    start_date?: any;    end_date?: any;}const initialValues: FilterSchema = {    start_date: '',    end_date: '',};

Initially they both are empty. But if one of them is selected, then other also needs to be selected. If none of them is selected then there is no need of validation. So I used yup for this in following way:

const filterSchema = yup.object().shape({  start_date: yup.string().when('end_date', {    is: value => value && value != '',    then: yup.string().required('Required'),  }),  end_date: yup.string().when('start_date', {    is: value => value && value != '',    then: yup.string().required('Required'),  }),});

But I am getting error message:

Cyclic dependency, node was: "end_date"

I am using filterSchema in Formik:

<Formik  onSubmit={facilityFilter}  validationSchema={filterSchema}  ....

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>