Skip to content

Dynamic :error/path for :fn validations #483

@mauricioszabo

Description

@mauricioszabo

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Not right now

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions