Cross validation in objects involving arrays: how to get the exact item that failed #1368
Unanswered
bettorinco
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello! Thanks in advance for considering my question :)
I have a doubt about cross field validation in an object schema with arrays inside.
Let's assume that I have this schema, representing an object with a
basePathand an array of paths calledassets:My goal is to check if the given assets (that I assume are all relative paths) exist when resolved against the
basePath.Since I do not have access to the
basePathinside the array ofassets, the obvious solution I found was to use acheckon the whole object, to ensure thateveryasset was an existing path.While this works as a validation, in case of error I am missing which one of the
assetsis invalid, since thecheckcallback allows to only return abooleanand I am forced to throw a generic message as shown in the example.So I'm wondering: is it possible to somehow intercept the exact path that gave the error?
Or even better: having a validation pipeline directly on the
assetschema, is it somehow possible to access the "parent" object, so that I can use thebasePath?For example something like this, with a sort of
contextavailable in the validation fn:Does anyone know a better approach to face this use case?
Thanks a lot in advance!
Beta Was this translation helpful? Give feedback.
All reactions