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

Question - Add support for disallowing a field #84

Open
piyushkantm opened this issue Dec 9, 2024 · 2 comments
Open

Question - Add support for disallowing a field #84

piyushkantm opened this issue Dec 9, 2024 · 2 comments

Comments

@piyushkantm
Copy link

piyushkantm commented Dec 9, 2024

"@vinejs/vine@^3.0.0"
"@vinejs/compiler@^3.0.0"

Is it possible to have ability to disallow a field conditionally?

export const createUserValidator = vine.compile(
  vine.object({
    country: vine.enum(Object.values(CountryEnum)),

    compliance_details: vine.object({
      entity_name: vine.string().trim(),
      tax_id: vine.string().trim(),
    }).forbiddenWhen("country", "in", [
      CountryEnum.ABC,
      CountryEnum.XYZ,
    ])
  })
);

Currently as far as i checked there is no way for the schema to reject if compliance_details exists along with country = .ABC or .XYZ

@thetutlage
Copy link
Contributor

Nope. Not yet!

However you can workaround it by making the compliance_details optional and requiring it when country is not in ABC or XYZ.

vine.object({
  country: vine.enum(Object.values(CountryEnum)),
  compliance_details: vine.object({
    entity_name: vine.string().trim(),
    tax_id: vine.string().trim(),
  }).optional().requiredWhen("country", "notIn", [
    CountryEnum.ABC,
    CountryEnum.XYZ,
  ])
})

@piyushkantm
Copy link
Author

Thanks. Would you be open to having this functionality? Can i contribute?

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