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

transform() not being executed after v0.31.1 #1260

Closed
lcdss opened this issue Feb 12, 2021 · 3 comments
Closed

transform() not being executed after v0.31.1 #1260

lcdss opened this issue Feb 12, 2021 · 3 comments
Labels

Comments

@lcdss
Copy link

lcdss commented Feb 12, 2021

I don't know if it's a feature or a bug, but since the version 0.32 the transform method is not executed anymore if combined with the when method. So now it's necessary call the transform method in both when cases (true and false) to get the same result as earlier versions.

const schema = object({
  type: number().required(),
  number: string()
    .transform((value) => value.replace(/\D/g, ""))
    .when("type", {
      is: 1, // CPF type
      then: string().required().cpf(),
      otherwise: string().required().cnpj()
    })
});

// Before v0.32
// { type: 1, number: "11111111111" }
schema.cast({ type: 1, number: "111.111.111-11" });

// After v0.31.1 (>= 0.32)
// { type: 1, number: "111.111.111-11" }
schema.cast({ type: 1, number: "111.111.111-11" });

I create an example on codesandbox to demonstrate this issue I had.

@lcdss lcdss changed the title Transform method does not execute anymore when combined with the when method Transform method not being executed after v0.31.1 Feb 12, 2021
@lcdss lcdss changed the title Transform method not being executed after v0.31.1 transform() not being executed after v0.31.1 Feb 12, 2021
@maiordom
Copy link

maiordom commented Mar 20, 2021

@lcdss
Copy link
Author

lcdss commented Jul 5, 2021

@jquense jquense added the bug label Jul 6, 2021
@jquense
Copy link
Owner

jquense commented Jul 6, 2021

oops definitely a bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants