-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Labels
Description
In cases where objects are validated against values, any keys are allowed. If a value is dependent on another nested inside an object, the requiredIf or requiredIfNot rules use dot notation for finding the target value (requiredIfNot: 'rootObj.someVal'). This requires a user to explicitly declare the key name in the model definition, which does not play well with dynamic keys.
const model = obey.model({
admin: {
type: 'object',
values: {
type: 'object',
required: true,
keys: {
valA: {
type: 'string',
requiredIfNot: 'valB' // This would check for a top-level valB prop,
}, // instead of the intended admin.<whateverKey>.valB
valB: {
type: 'string',
requiredIfNot: 'valA' // and vice versa
}
}
}
}
})