Skip to content

Commit cac6a27

Browse files
Update README.md
1 parent a4c458f commit cac6a27

File tree

1 file changed

+83
-1
lines changed

1 file changed

+83
-1
lines changed

README.md

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Read the documentation for the file module at [#file-validators](#file-validator
112112
* **Dependent validation**
113113
* **Require "one-of"**
114114

115-
Read the documentation for this module at [http://formvalidator.net/#logic](http://www.formvalidator.net/#logic)
115+
Read the documentation for this module at [/#logic](#logic)
116116

117117
### Module: sepa
118118

@@ -875,6 +875,88 @@ Use the attribute <code>data-validation-ratio</code> to validate that the upload
875875
<input data-validation="ratio mime" data-validation-allowing="jpg" break="" data-validation-dimension="min100" data-validation-ratio="8:10-12:10" />
876876
```
877877

878+
## Logic
879+
880+
### Validators depending on each other
881+
882+
Use the attributes <code>data-validation-depends-on</code> to configure that an input is optional as long as another input is left without an answer.
883+
884+
```
885+
<!-- Require e-mail only if checkbox is checked -->
886+
<p>
887+
<strong>Contact me:</strong>
888+
<input name="do-contact" type="checkbox" value="1" />
889+
</p>
890+
<p>
891+
<strong>E-mail:</strong>
892+
<input
893+
type="text"
894+
data-validation="email"
895+
data-validation-depends-on="do-contact"
896+
/>
897+
</p>
898+
```
899+
900+
```
901+
<!-- Require a state to be given if the user comes from either USA or Canada -->
902+
<p>
903+
<strong>Country:</strong>
904+
<input
905+
type="text"
906+
name="country"
907+
id="country-input"
908+
data-validation="country"
909+
/>
910+
</p>
911+
912+
<p>
913+
<strong>State:</strong>
914+
<input type="text"
915+
name="state" break=""
916+
data-validation="required" break1=""
917+
data-validation-depends-on="country" break2=""
918+
data-validation-depends-on-value="usa, canada"
919+
/>
920+
</p>
921+
</div>
922+
...
923+
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
924+
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.3.26/jquery.form-validator.min.js"></script>
925+
<script>
926+
$.validate({
927+
modules : 'location, logic',
928+
onModulesLoaded : function() {
929+
$('#country-input').suggestCountry();
930+
}
931+
});
932+
</script>
933+
```
934+
935+
### Require only one out of several inputs
936+
937+
Use the attribute <code>data-validation-optional-if-answered</code> to tell the validator that only one, out of a group of inputs, requires an answer.
938+
939+
```
940+
<p>
941+
<strong>Home phone number:</strong>
942+
<input name="home-phone"
943+
data-validation="number" break=""
944+
data-validation-optional-if-answered="cell-phone, work-phone" />
945+
</p>
946+
<p>
947+
<strong>Cell phone number:</strong>
948+
<input name="cell-phone"
949+
data-validation="number" break=""
950+
data-validation-optional-if-answered="home-phone, work-phone" />
951+
</p>
952+
<p>
953+
<strong>Work phone number:</strong>
954+
<input name="work-phone"
955+
data-validation="number" break=""
956+
data-validation-optional-if-answered="home-phone, cell-phone" />
957+
</p>
958+
</div>
959+
```
878960

879961
## Changelog
880962

0 commit comments

Comments
 (0)