title: Yup to validate on the base of function dispatch
body: <p><strong>I Want to Make Validation optional for only password and confirm password in the case when updateUser action Dispatch</strong></p>
  <p>How can I stop the validation for a specific user action call?
  this is the yup schema</p>
  <pre><code>const RegisterSchema = Yup.object().shape({
      code: Yup.string()
          .required(&quot;Employee Code is required!&quot;)
          .max(8, &quot;Employee Code should not exceed 8 characters&quot;)
          .matches(/^[0-9]+$/, &quot;Only number are allowed for this field&quot;),
      firstName: Yup.string()
          .required(&quot;First name is required!&quot;)
          .max(16, &quot;First name should not exceed 16 characters&quot;)
          .required(&quot;First name is required&quot;)
          .matches(/^[aA-zZ]+$/, &quot;Invalid First name&quot;),
      lastName: Yup.string()
          .required(&quot;Last name is required!&quot;)
          .max(16, &quot;Last name should not exceed 16 characters&quot;)
          .required(&quot;Last name is required&quot;)
          .matches(/^[aA-zZ]+$/, &quot;Invalid Last name&quot;),
      userName: Yup.string()
          .required(&quot;User name is required&quot;)
          .matches(/^[^\s]+(\s+[^\s]+)*$/, &quot;Invalid User name&quot;)
          .max(16, &quot;User name should not exceed 16 characters&quot;),
      address: Yup.string()
          .required(&quot;Address is required&quot;)
          .matches(/^[^\s]+(\s+[^\s]+)*$/, &quot;Invalid Address&quot;),
      role: Yup.mixed().required(&quot;Role is required!&quot;),
      desigination: Yup.mixed().required(&quot;Desigination is required!&quot;),
      department: Yup.mixed().required(&quot;Department is required!&quot;),
      date: Yup.mixed().required(&quot;Date is required&quot;),
      city: Yup.mixed().required(&quot;City name is required&quot;),
      country: Yup.mixed().required(&quot;Country name is required&quot;),
      phone: Yup.string()
          .matches(
              /^(?:(?:\(?(?:00|\+)([1-4]\d\d|[1-9]\d?)\)?)?[\-\.\\\\/]?)?((?:\(?\d{1,}\)?[\-\.\\\\/]?){0,})(?:[\-\.\\\\/]?(?:#|ext\.?|extension|x)[\-\.\\\\/]?(\d+))?$/i,
              &quot;Phone number should be numeric only!&quot;
          )
          .required(&quot;Phone number is required&quot;)
          .min(10, &quot;Phone number must be at least 10 characters&quot;)
          .max(10, &quot;Phone number must be at least 10 characters&quot;),
  
      email: Yup.string()
          .email(&quot;Email must be a valid email address&quot;)
          .required(&quot;Email is required&quot;),
      password: Yup.string().when(&quot;check&quot;, {
          is: (check) =&gt; true,
          then: Yup.string()
              .required(&quot;Password is required&quot;)
              .matches(
                  /^(?=(?:.*[A-Z].*){1})(?=.*\d)(?=.*[@$!%*#?&amp;])[A-Za-z\d@$!%*#?&amp;]{8,}$/,
                  &quot;Must Contain 8 Characters,  One Uppercase, One Lowercase, One Number and one special case Character&quot;
              ),
          // otherwise:
      }),
      confirmPassword: Yup.string().when(&quot;check&quot;, {
          is: (check) =&gt; true,
          then: Yup.string()
              .required(&quot;Confirm Password is required&quot;)
              .oneOf([Yup.ref(&quot;password&quot;), null], &quot;Passwords must match&quot;),
          // otherwise:
      }),
  });
  </code></pre>
  <p>I tried using When is condition to make it work but it only happens to work with a boolean attribute</p>
  <pre><code>const formik = useFormik({
      enableReinitialize: true,
      initialValues: userDetail,
      validationSchema: RegisterSchema,
      onSubmit: async (values) =&gt; {
          let roleName: any = [];
          values.role.forEach((role) =&gt; {
              roleName.push(role.label);
          });
  
          let x: any = location.state;
          if (location.state !== undefined) {
              await dispatch(
                  updateUser({
                      id: x.userId,
                      firstName: values.firstName,
                      lastName: values.lastName,
                      userName: values.userName,
                      desigination: values.desigination.value,
                      department: values.department.value,
                      role: roleName ? roleName : roles[0],
                      date: values.date,
                      address: values.address,
                      city: values.city,
                      country: values.country,
                      email: values.email,
                      password: values.password,
                      confirmPassword: values.confirmPassword,
                      phone: values.phone,
                      code: values.code,
                  })
              );
          } else {
              await dispatch(
                  addUser({
                      firstName: values.firstName,
                      lastName: values.lastName,
                      userName: values.userName,
                      desigination: values.desigination.value,
                      department: values.department.value,
                      role: roleName ? roleName : roles[0],
                      date: values.date,
                      address: values.address,
                      city: values.city,
                      country: values.country,
                      email: values.email,
                      password: values.password,
                      confirmPassword: values.confirmPassword,
                      phone: values.phone,
                      code: values.code,
                  })
              );
          }
      },
  });
  </code></pre>