I can't use external fields in object.members validation in validation does anyone know how to solve? #4181
Unanswered
reinaldobatista
asked this question in
Help
Replies: 1 comment 3 replies
-
After digging into the requiredWhen code I found that it uses a helper called getFieldValue to get the value of the fields in your schema. So in order to validate from the root of your schema you need to prepend a '/' const schema = schema.create({
topLevelProperty: schema.string(),
myObject: {
lowerLevelProperty: schema.string.optional([rules.requiredWhen('/topLevelProperty', '=', 'myExpectedValue')])
}
}) If you don't provide the '/' it will search from within your current object. Here is the original explanation found in /**
* Returns the field value for a given pointer. If pointer starts
* with `/`, then it will be searched from the root of the
* object, otherwise it's searched from the nearest tip
*/
export declare function getFieldValue(field: string, root: any, tip: any): any; Also, it would be nice to have this explained in the docs. |
Beta Was this translation helpful? Give feedback.
3 replies
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.
-
in this case below for example does not work
another case is when the object has more than one level
Beta Was this translation helpful? Give feedback.
All reactions