title: Joi - how to check when other key's value is null/empty
body: <p>I am having trouble trying to validate a JSON file, to be more specific I am having trouble with a <strong>when</strong> condition.</p>
  <p>I have a <strong>a</strong> key that has to be a past date, and isn't required. Then I have a <strong>b</strong> key that should be an url and <em>if</em> <strong>a</strong> <em>is null/empty,</em> <strong>b</strong> <em>can be empty, otherwise must be required</em>.</p>
  <p>I'll leave my code below to make it clear, but right now I'm not getting any error if <strong>b</strong> is null but <strong>a</strong> isn't.</p>
  <pre><code>a: Joi.date().less(&quot;now&quot;).raw().optional().allow(null, &quot;&quot;),
  b: Joi.string()
    .uri({ scheme: [/https?/] })
    .when(&quot;a&quot;, {
      is: Joi.any().empty(),
      then: Joi.optional().allow(null, &quot;&quot;),
      otherwise: Joi.required(),
    }),
  </code></pre>