Having an issue getting my validation to work correctly. Using jquery.validate to do a basic login form with only a few fields needing to be required. I am keeping the input button disabled until all validations have passed but it is not working correctly. The error for the second input field is showing up as soon as focus leaves the first field and displaying an error message. Would like to only have the error message show up like it does usually for jquery.validate after the field has received focus and then loses focus and detects an error.
So basically, keep the submit button disabled until all fields are valid but do not show the error message until the field has been activated and then failed.
Here is my fiddle now:
Here is the JS:
$('#my-login').validate({
onkeyup: false,
ignore: ":disabled,:hidden",
submitHandler: function (form) {
form.submit();
}
});
$('#my-login input').on('blur', function () {
var empty = false;
$('#my-login > input').each(function() {
if ($(this).val() == '') {
empty = true;
}
});
if (this.form != (empty) && $('#my-login').valid()) {
$('#singleSubmitBtnLoan').prop('disabled', false);
} else {
$('#singleSubmitBtnLoan').prop('disabled', 'disabled');
}
});
$("#singleSubmitBtnLoan").bind('click', function () {
if ($('#my-login').valid()) {
$('#my-login').submit();
}
});
And my form here:
<form id="my-login" name="my-login-form" action="notYetDude" method="get">
<div>
<label for="lastName" class="proximo">Last Name</label>
<input type="text" id="lastName" name="lastName" aria-required="true" class="inputExtender largeFont" maxlength="50" />
</div>
<div class="inputAdjust">
<label for="userNum">Last 4 Digits of userNum</label>
<input type="tel" id="userNum" name="userNum" aria-required="true" maxlength="4" size="5" />
</div>
<div>
<label for="appId" class="proximo" id="tt1-label">Reference Number</label>
<input type="tel" id="appId" name="appId" aria-required="true" maxlength="10" size="11" value="12345678" />
</div>
<div style="margin-top: -4px">
<input type="submit" id="singleSubmitBtnLoan" class="dsu-button lightBlue dsuBtnStyleLogin" disabled="true">Sign In</input>
</div>
submitHandlerif the only thing you're going to put in there is the default function. You also don't need theignoreoption for the same reason... the plugin will ignore all hidden and disabled fields by default.