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

Want a way to have custom logic based on other values in my schema #120

Closed
ziyak97 opened this issue Aug 24, 2023 · 3 comments
Closed

Want a way to have custom logic based on other values in my schema #120

ziyak97 opened this issue Aug 24, 2023 · 3 comments
Assignees
Labels
duplicate This issue or pull request already exists enhancement New feature or request workaround Workaround fixes problem

Comments

@ziyak97
Copy link

ziyak97 commented Aug 24, 2023

An example would be

  privacyPolicyUrl: string([
    (input, context) => {
      if (!context.isPrivacyPolicyAvailable && !input) {
        return {
          issue: {
            validation: "custom",
            message: "Privacy Policy URL is required",
            input,
          },
        };
      }
      return { output: input };
    },
    url("Please enter a valid URL"),
  ]),

i am not sure if something like this already exists any suggestions would be appreciated

@fabian-hiller
Copy link
Owner

Hey, thanks for creating this discussion. Please read through the following three issues and discussions and let me know if your questions are answered. Otherwise, I can try to address your specific use case.

@fabian-hiller fabian-hiller self-assigned this Aug 24, 2023
@fabian-hiller fabian-hiller added duplicate This issue or pull request already exists enhancement New feature or request workaround Workaround fixes problem labels Aug 24, 2023
@ziyak97
Copy link
Author

ziyak97 commented Aug 24, 2023

hey thanks for the prompt reply. sadly these don't work for my usecase as these checks happen post the initial schema check.

my usecase is for someone to enter their privacy policy url which needs to be validated as a url. if they however check a box lets say a boolean of noPrivacyPolicy, then the privacy policy url is no longer required. instead they would have to enter a reason as to why they would not put the same which would now be required (it would be optional if noPrivacyPolicy was not selected). there are other fields in my form also so ideally i would NOT want my privacy policy related validations to happen only after those other validations go through successfully.

@fabian-hiller
Copy link
Owner

You can build that with union.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists enhancement New feature or request workaround Workaround fixes problem
Projects
None yet
Development

No branches or pull requests

2 participants