Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

254
Views
Formik Yup not working properly `.test()` custom validation setting for one input impact all others input

so i have this schema validation :

const validationSchema = Yup.object().shape({
    username: Yup.string()
      .min(2, 'votre surnom doit contenir minimum 2 caractères')
      .max(30, '30 caractères maximum autorisés')
      .required('Veuillez renseigner un pseudo'),
    email: Yup.string()
      .email('Veuillez renseigner une adresse mail valide')
      .required('Ce champs est obligatoire.')
      .test(
        'emailCheck',
        'cet est email déjà utiliser, veuillez en choisir un autre',
        async (value) => {
          const res = await AuthenticationService.checkEmail(value);
          if (res) {
            return false;
          } else {
            return true;
          }
        }
      ),
    password: Yup.string()
      .required('Ce champs est obligatoire.')
      .min(
        8,
        'Le mot de passe doit contenir 8 caractères ou plus, dont au moins un de chaque type : majuscule, minuscule, chiffre et spécial.'
      )
      .minLowercase(1, 'le mot de passe doit contenir au moins 1 lettre minuscule')
      .minUppercase(1, 'le mot de passe doit contenir au moins 1 lettre majuscule')
      .minNumbers(1, 'le mot de passe doit contenir au moins 1 chiffre')
      .minSymbols(1, 'le mot de passe doit contenir au moins 1 caractère spécial'),
    passwordConfirmation: Yup.string().oneOf(
      [Yup.ref('password'), null],
      'Les mots de passe doivent correspondre'
    )
  });

i'm testing if the email already exist it's work well but the test affecting all other input when i quit the username input and go on the password input for example the test for the email input is call. if i try to pu a test like a checkUsername function on the username input like this:

username: Yup.string()
  .min(2, 'votre surnom doit contenir minimum 2 caractères')
  .max(30, '30 caractères maximum autorisés')
  .required('Veuillez renseigner un pseudo')
  .test(
    'usernameCheck',
    'cet est identifiant déjà utiliser, veuillez en choisir un autre',
    async (value) => {
      const res = await AuthenticationService.checkUsername(value);
      if (res) {
        return false;
      } else {
        return true;
      }
    }
  ),
email: Yup.string()
  .email('Veuillez renseigner une adresse mail valide')
  .required('Ce champs est obligatoire.')
  .test(
    'emailCheck',
    'cet est email déjà utiliser, veuillez en choisir un autre',
    async (value) => {
      const res = await AuthenticationService.checkEmail(value);
      if (res) {
        return false;
      } else {
        return true;
      }
    }
  ),

the checkEmail function email still be called for the username input.

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!