Skip to content

Account for dynamic keys in nested conditional requires #82

@psvet

Description

@psvet

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
        }
      }
    }
  }
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions