Yup validation in react for all
Yup validation in react for all with when conditional HousingValidationSchema = () => Yup.object().shape({ isCurrent: Yup.boolean (), country: Yup.number (), // Country is a dropdown state: Yup.string ().when( 'country' , { is : (value) => Enum.Countries.eUSA === value, then: Yup.string ().required( 'Enter a state' ), }), occupancyStatus: this.props.showOccupancyStatusAndDuration ? ! this .props.hideOccupancyStatus && this .props.isCurrent ? Yup. number ().required( 'Select an occupancy status' ) : Yup. number () : Yup. number (), address: Yup.string ().required( 'Enter an address' ), zipCode: Yup.string ().when( 'country' , { is : (value) => Enum.Countries.eUSA === value, then: Yup.string () .required( 'Enter a ZIP code' ) .matches( /^\d{5}(?:[-\s]\d{4})?$|^\d{9}$/ , { message : 'ZIP code format is incorrect' }), }), c...