Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OneOf and notOneOf do not handle null and undefined in the error message. #768

Closed
DaddyWarbucks opened this issue Feb 1, 2020 · 0 comments · Fixed by #1757
Closed

OneOf and notOneOf do not handle null and undefined in the error message. #768

DaddyWarbucks opened this issue Feb 1, 2020 · 0 comments · Fixed by #1757

Comments

@DaddyWarbucks
Copy link
Contributor

Describe the bug
When using the oneOf or notOneOf with null and undefined the values are not interpolated into the error message properly.

const oneOfSchema = yup.object({
    name: yup
      .string()
      .nullable()
      .oneOf([null, undefined])
  });

// "name must be one of the following values: , "

// ^^ Notice the `null` and `undefined` are not "stringified" into the error message.

To Reproduce

https://codesandbox.io/s/dreamy-elgamal-7d2fv

Expected behavior
When using null or undefined in the oneOf or notOneOf methods the error message will interpolate those values correctly.

Platform (please complete the following information):

  • Chrome 79 on macOS (Mojave)
  • Version: 0.26.10

Additional context
This may seem silly that someone would mark a schema as nullable but then also set the schema as oneOf([null]), but I have a use case where when using when I believe this makes sense.

stripe_id: yup
      .string()
      .label('Stripe ID')
      .required()
      .nullable()
      .when('type', (type, schema) => {
        // If type is stripe, stripe_id cannot be null and must be provided
        // Otherwise the value must be null
        return type === 'stripe'
          ? schema.nullable(false)
          : schema.oneOf([null]);
      })
@jquense jquense closed this as completed Aug 20, 2022
jquense added a commit that referenced this issue Aug 22, 2022
closes: #768 #104

BREAKING CHANGE: previously `oneOf` required adding `null` explicitly to allowed values when using oneOf. Folks have found this confusing and unintuitive so I am deferring and adjusting the behavior
jquense added a commit that referenced this issue Aug 22, 2022
closes: #768 #104

BREAKING CHANGE: previously `oneOf` required adding `null` explicitly to allowed values when using oneOf. Folks have found this confusing and unintuitive so I am deferring and adjusting the behavior
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants