Validation plugin auto clear error message after chaning value text box
Hi everyone,
I use validattion plugin to validate 2 textbox (date of birth - DOB, issued date - ISSDT) using datepicker plugin. DOB textbox is checked over 18 years old (It means now - DOB >= 18). Another one is checked for greatering than DOB: 14 years old (It means ISSDT - DOB >= 14). I selected wrong value for all textbox to display error message 1, error message 2. When i changed from wrong value in DOB to right value and it's valid for ISSDT, but it's only to clear message 1. How do i do to clear all error message when every textbox are right?
Help me, please. Thanks in advance :)
- $("#mainForm").validate({
- messages:
- {
- txtDOB:
- {
- checkDateOfBirth: "Chủ tài khoản chưa đủ 18 tuổi. Hãy nhập lại!",
- },
- txtIdIssueDate:
- {
- checkIdentityCard: "Kiểm tra lại ngày cấp CMT và ngày sinh!"
- }
- },
- invalidHandler: function(event, validator) {
- event.preventDefault();
- event.stopPropagation();
- }
- });
-
- $.validator.addMethod("checkDateOfBirth", function(value, element){
- var inputDate = $('#txtDOB').val();
- var currdate = new Date();
- var yearInput = 18;
- return compareDate(inputDate, currdate, yearInput, '>=');
- });
-
- $.validator.addMethod("checkIdentityCard", function(value, element){
- var frDate = $("#txtDOB").val();
- var toDate = $("#txtIdIssueDate").val();
- var yearInput = 14;
- return compareDateStr(frDate, toDate, yearInput, '>=');
- });
-
- var test = {
- txtCheckDateOfBirth: {
- checkDateOfBirth: true
- },
- txtIdIssueDate: {
- checkIdentityCard: true
- }
- }
-
- $("#txtDOB").rules('add', test['txtCheckDateOfBirth']);
- $("#txtIdIssueDate").rules('add', test['txtIdIssueDate']);
- $(".datepicker").datepicker('option', {
- onClose: function(dateText, inst){
- $(this).valid();
- }
- });