Reset validation if disabled
by Michel Plungjan
HTML
<script src="http://jquery.bassistance.de/validate/jquery.validate.js"></script>
<div>
<form id="clientConfigurationForm">
<input type="checkbox" id="chk1" checked />
<label for="chk1">Enable</label>
<br />
<select id="sel1" name="seltest">
<option>Hello</option>
</select>
<br />
<input type="input" name="inputtest" class="required number" /><br />
<input type="submit" name="submit" value="Save" />
<br />
</form>
</div>
CSS
.green {
background-color:green
}
JavaScript
var val;
$("#clientConfigurationForm").on("change", "input[type=checkbox]", function () {
val.resetForm();
$(this)
.closest("div")
.find("input, select")
.not(this)
.not(":submit")
.prop("disabled", !$(this).prop("checked"))
.not(":disabled")
.each(function () {
$(this).valid();
});
});
val = $("#clientConfigurationForm").validate({
onkeyup: function (element) {
$(element).valid();
},
focusInvalid: false,
submitHandler: function (form) {
alert("submitted");
}
});