How to use the yup.setLocale function in yup

To help you get started, we’ve selected a few yup examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github treebohotels / leaf-ui / src / Form / validation.js View on Github external
test(value) {
        return value == null || +value > this.resolve(moreThan);
      },
    });
  },

  positive(msg = '${path} must be a positive amount') {
    return this.min(0, msg);
  },

  negative(msg = '${path} must be a negative amount') {
    return this.max(0, msg);
  },
});

yup.setLocale(locale);
yup.amount = AmountSchema;
yup.addMethod(yup.string, 'name', function nameMethod(message) {
  const nameRegex = /^[a-zA-Z]+( [a-zA-Z]+)*$/;
  // eslint-disable-next-line no-template-curly-in-string
  return this.test('name', locale.string.name, function nameTest() {
    return nameRegex.test(this.options.originalValue) || this.createError({ message });
  });
});

export default yup;
github kre8-kubernetes / kre8 / src / client / containers / HomeContainer.js View on Github external
setAWSCredentials(e) {
    e.preventDefault();
    const { awsAccessKeyId, awsSecretAccessKey, awsRegion } = this.state;
    const awsCredentials = { awsAccessKeyId, awsSecretAccessKey, awsRegion };
    // Create custom instructions for Yup error handling
    setLocale({
      mixed: { notOneOf: 'AWS Region is required' },
      string: {
        min: 'Please enter a valid AWS credential',
        max: 'Please enter a valid AWS credential',
      },
    });
    // Define Yup Error Schema
    const awsCredentialsSchema = object().strict().shape({
      awsAccessKeyId: string().required('Please enter a valid AWS Access Key Id').min(15).max(40),
      awsSecretAccessKey: string().required('Please enter a valid AWS Secret Access Key').min(30).max(50),
      awsRegion: mixed().required('AWS Region is required').notOneOf(['default']),
    });
    awsCredentialsSchema.validate(awsCredentials, { abortEarly: false })
      .then((data) => {
        this.setState(prevState => ({
          ...prevState,
github felipepastorelima / react-pet-hotel / 3-Customization / 21-Fee calculation / frontend / src / i18n / index.js View on Github external
export function setLanguageCode(arg) {
  if (!languages[arg]) {
    throw new Error(`Invalid language ${arg}.`);
  }

  moment.locale(arg);
  localStorage.setItem('language', arg);

  if (getLanguage().dictionary.validation) {
    setYupLocale(getLanguage().dictionary.validation);
  }
}