Skip to content

Required If Example #252

Closed
Closed

Description

Hi everyone,

Is there an example of the required_if rule? It's not clear what another field in required_if:anotherfield,trueshould be. Is this the id, name or just a variable?

I want to use this on a checkbox. I tried name, but it does not work. The checkbox input itself is hidden.

Thanks for the explanation!
Katia

Activity

  1. mikeerickson commented on Mar 7, 2018

    @mikeerickson
    Owner
    let validation = new Validator({
      cb1: 0,
      cb2: 0
    }, {
      cb1: [{ required_if: ['cb2', "checked" }]
    });
    
    validation.fails(); // true
    validation.passes(); // false
    <input id="cb1" name="cb2" type="checkbox" value="checked" checked>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions