Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account for dynamic keys in nested conditional requires #82

Open
psvet opened this issue Jun 21, 2019 · 0 comments
Open

Account for dynamic keys in nested conditional requires #82

psvet opened this issue Jun 21, 2019 · 0 comments
Labels

Comments

@psvet
Copy link
Owner

psvet commented Jun 21, 2019

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
        }
      }
    }
  }
})
@psvet psvet added the bug label Jun 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant