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

Dynamic :error/path for :fn validations #483

Open
mauricioszabo opened this issue Jul 22, 2021 · 0 comments
Open

Dynamic :error/path for :fn validations #483

mauricioszabo opened this issue Jul 22, 2021 · 0 comments

Comments

@mauricioszabo
Copy link
Contributor

mauricioszabo commented Jul 22, 2021

Hi, based on this issue:
#474

I was trying to do something similar. In my case, I have some conflicting info: for example, if I chose a specific type of document, I don't need to provide additional info, for example. To allow that I was using an :fn schema like so:

[:and
 [:map
  [:document-type string?]
  [:document-state string?]
  [:document-country string?]]
 [:fn {:error/message "Mandatory field for this document"
       :error/path [???]
  (fn [{:keys [...]}]
    ...rules-to-check-for-fields...)]]

So, the problem is that if I want to put the error on the :document-state for example if document is type A, and on :document-country if document is of type B. I have no way of doing this today.

For this simple example, it's not a problem, but when the logic is complicated, or in some of the examples of the issue #474, you have a field that conflicts with other, I think it could be a great addition to just let the validation function define the path, for example, or maybe some other solution... WDYT?

Another good addition could be to allow multiple paths (when, for example, document is type C, it'll require both "state" and "country" to be filled)

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

1 participant