I have a function which compares two fields.
$.validator.addMethod("validatormethod", function (value, element) {
return $('#Field1').val() > $('#Field2').val()
}, "Test");
The form is dynamic and hence the form is validated using each:
$('.validateclass').each(function () {
$(this).rules('add', {
validatormethod: true,
messages: {validatormethod: "Test" }
})
});
$('.validateclass2').each(function () {
$(this).rules('add', {
required: true,
messages: {required: "This field is required" }
})
});
$('#myForm').valid();
Now my problem is the message Test appears as soon as the page loads. It should appear only after the field is compared. I know it is due the the line $('#formSaveComponent').valid();. But I want the required message to appear when the page loads. Is there some way I can get this done using jQuery Validate plugin.
.valid()when the page loads and what your title is supposed to mean. Showing error message after validation is the default behavior.Testafter the submit/tab event.