resolvers icon indicating copy to clipboard operation
resolvers copied to clipboard

It is not possible to use your types for Yup validation

Open freiserg opened this issue 2 years ago • 4 comments

Describe the bug How to add a custom type when not all fields are inferred from the form?

To Reproduce Steps to reproduce the behavior:

We use so props:

export type FormValues = {
  account: Account;
  currency: Currency;
  amount: string;
};

Account and Account types have many props.

type Account {
  accountId: string;
  name: string;
  type: Type;
  ...
}

account and currency fields are custom Select components.

We need to check that an element is selected.

const validationSchema = Yup.object().shape({
  account: Yup.object().required('Account is required'),
  currency: Yup.object().required('Currency is required'),
  amount: Yup.string().required('Amount is required.')
});

Codesandbox link (Required) codesandbox link.

Expected behavior The yupResolver function should not complain about the given formSchema.

freiserg avatar Aug 25 '23 15:08 freiserg

Any updates on this? We also had to downgrade to 3.1.0/couldn't upgrade to latest in our codebase, which is really unfortunate.

Shentoza avatar Jan 08 '24 08:01 Shentoza

I have a same problem. When I have some complex type for form, sometimes I have in form values which I dont need for validation and if I have like enum as a type, then is the end. Usually I have as form type graphql input type. In this type can be as type for value null, undefined or type of value. But from yup resolver I hade a little bit another type. Value or null. This maybe is my problem.Something missing in yup validation schema (maybe optional). Now I must downgrade to version 3.1.0.

pronovaso avatar Jan 10 '24 20:01 pronovaso