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

Optional validation #153

Closed
worfoual opened this issue Jun 24, 2014 · 2 comments
Closed

Optional validation #153

worfoual opened this issue Jun 24, 2014 · 2 comments

Comments

@worfoual
Copy link

It's not really an issue but I try to do somethink and I just can't achieve it.
I have an input field (text): company_name not required
I have an input field company_adres (text) and I want this one to be required only if company_name is not empty

Is it possible to get this working? I know it works with a checkbox: data-validation-if-checked
But I can't get it working with a input field type text.
Sorry for my poor english.
My regards,
Francois

@victorjonsson
Copy link
Owner

This is actually a good feature request. The attribute data-validation-if-checked should be renamed to data-validation-depends-on and should work with any type of input.

@victorjonsson
Copy link
Owner

This feature has now moved into the module "logic". Using the old attribute data-validation-if-checked is considered deprecated and will trigger a console warning.

Validate input if a checkbox is checked

<p>
   E-mail:
   <input data-validation="email" data-validation-depends-on="agreement" />
</p>
<p>
  Lorem te ipsum
  <input type="checkbox" name="agreement" value="1" />
</p>
...
<script>
   $.validate({
     modules: 'logic'
   });

Require state if user comes from either USA or canada

<p>
   Home country:
   <select name="country">
       ...
       <option value="USA">USA</option>
       <option value="Uganda">Uganda</option>
       ....
   </select>
</p>
<p>
   State:
   <input 
      name="state"
      data-validation="required"
      data-validation-depends-on="country"
      data-validation-depends-on-value="usa, canada"
    />
</p>
...
<script>
$.validate({
   modules: 'logic'
});
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants