Skip to content

Validator requiredWhen #3730

Answered by galaczi
galaczi asked this question in Help
Discussion options

You must be logged in to vote

Solved it with a custom validator:

validator.rule('requiredWhenFalse', (value: boolean, compiledOptions: string, options) => {
  if(options.root[compiledOptions[0]] === 'false' && !value) {
    options.errorReporter.report(
      options.pointer,
      'requiredWhenFalse',
      'You must choose one',
      options.arrayExpressionPointer
    )
  }

  return
})

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by galaczi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
1 participant