Posts

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...

YUP Validation for String and Array

Image
 YUP Validation for string and Array  purposeTypes : Yup.lazy(() => { if ( this .state.isMLPurposeTypes) { return Yup.string().notRequired(); } return Yup.array().min( 1 , 'Select Asset Type' ); }), decisionFlowValidationSchema = Yup.object().shape({ flowDescription : Yup.string().required( 'Flow Description can not be blank' ), appType : Yup.string().required( 'Select App Type' ), isSinglePaymentLoan : Yup.string().required( 'Select Single Payment Loan' ), calculateBasedOn : Yup.lazy(() => { if ( this .state.isCalculateBasedOnHidden) { return Yup.string().notRequired(); } return Yup.string().required( 'Select Calculate Based On' ); }), assetTypes : Yup.lazy(() => { if ( this .state.isHEVLAssetType) { return Yup.array().min( 1 , 'Select Asset Type' ); } return Yup.array().notRequired(); }), purposeTypes : Yup.lazy(() => { if ( this .s...