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

There is no way to tell vee-validate our class instance is whole and no need for PartialDeepObject #4734

Closed
2 of 5 tasks
sharifzadesina opened this issue Apr 24, 2024 · 3 comments

Comments

@sharifzadesina
Copy link

What happened?

It seems there is no way to tell vee-validate to treat our class instance as a whole and not treat each property separately.
Imagine this:

<CountrySelect v-model="country" />
const schema = object({
  country: mixed((inp): inp is Country => inp instanceof Country).required().label('Country'),
});

const form = useForm({ validationSchema: toTypedSchema(schema) });

const [country] = form.defineField('country');

country ref is supposed to be of type Country | undefined, but it is of type PartialDeepObject<Country> | undefined.
the input, returns "country" as a whole or no country at all.

Reproduction steps

No response

Version

Vue.js 3.x and vee-validate 4.x

What browsers are you seeing the problem on?

  • Firefox
  • Chrome
  • Safari
  • Microsoft Edge

Relevant log output

No response

Demo link

No need

Code of Conduct

@sharifzadesina
Copy link
Author

The one thing I can do is explicitly defining TValue, but this is not ideal, because vee-validate is supposed to get the type from yup:

const [country] = form.defineField<'country', Country>('country');

@logaretm
Copy link
Owner

logaretm commented Apr 28, 2024

This is a bit of a limitation sadly because there is no way for vee-validate to know if the country itself is the field or if it is a container for a bunch of fields.

Think about it like this, a phone object with name, flag properties can be expressed in two ways with fields:

  • A select input that picks the country object from its options. The field emits the { name, flag } object as a value. This looks like your case here.
  • Or a couple of nested fields country.name and country.flag and while this may not make sense in this example it does for other types of objects.

There is no way for vee-validate to know where the nesting stops and where the field is actually, all it knows that it has a schema and that schema leafs can be fields. So that's why it uses the PartialDeep type here.

Unless I work on a completely different schema validation system that takes this into account, I don't think I can do much here.

@sharifzadesina
Copy link
Author

@logaretm Yup already treats the country as a whole when you use mixed validator. there is no problem in the schema validation part I suppose.
It is vee-validate that adds partial deep to everything.

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

No branches or pull requests

2 participants