Jquery Form Validation works only once -
i using jquery form validation :
$('#form').validate({ errorelement: 'span', //default input error message container errorclass: 'help-block help-block-error', // default input error message class focusinvalid: false, // not focus last invalid input ignore: "", // validate fields including form hidden input rules: { "cash": { equalto: "#password" }, "custfirstname": { required: true }, "custlastname": { required: true }, "custemailaddress": { required: true, email: true, }, "custmobileno": { required: true, minlength:9, maxlength:10, number: true }, "adultfirstname[]": { required: () => { return $("input[name='adultfirstname[]']").filter(function() { return $.trim($(this).val()).length > 0 }).length == 0 } }, "adultlastname[]":{ required: () =>{ return $("input[name='adultlastname[]']").filter(function() { return $.trim($(this).val()).length > 0 }).length == 0 } }, "adultdob[]": { required: () => { return $("input[name='adultdob[]']").filter(function() { return $.trim($(this).val()).length > 0 }).length == 0 }, dateformat:true }, "adultpassportno[]": { required: () => { return $("input[name='adultpassportno[]']").filter(function() { return $.trim($(this).val()).length > 0 }).length == 0 }, }, "childfirstname[]": { required: () => { return $("input[name='childfirstname[]']").filter(function() { return $.trim($(this).val()).length > 0 }).length == 0 }, }, "childlastname[]": { required: () => { return $("input[name='childlastname[]']").filter(function() { return $.trim($(this).val()).length > 0 }).length == 0 }, }, "childdob[]": { required:() =>{ return $("input[name='childdob[]']").filter(function() { return $.trim($(this).val()).length > 0 }).length == 0 }, dateformat:true }, "childpassportno[]": { required: () => { return $("input[name='childpassportno[]']").filter(function() { return $.trim($(this).val()).length > 0 }).length == 0 }, }, "infantfirstname[]": { required: () => { return $("input[name='infantfirstname[]']").filter(function() { return $.trim($(this).val()).length > 0 }).length == 0 }, }, "infantlastname[]": { required: () => { return $("input[name='infantlastname[]']").filter(function() { return $.trim($(this).val()).length > 0 }).length == 0 }, }, "infantdob[]": { required: () => { return $("input[name='infantdob[]']").filter(function() { return $.trim($(this).val()).length > 0 }).length == 0 }, dateformat:true }, "infantpassportno[]": { required: () => { return $("input[name='infantpassportno[]']").filter(function() { return $.trim($(this).val()).length > 0 }).length == 0 }, }, }, invalidhandler: (event, validator) => { $(".errorfield").hide(); _.each(validator.errorlist, (e: any) => { if (e.method == "equalto") { alert("payment gateway not available please select points only") } else if (e.method == "greaterthan") { var confirm = $(".bs-example-modal-sm"); confirm.modal('show'); $('.modal-body').html(e.message); } else $(e.element).parent().find("p").text(e.message).show(); }); }, errorplacement: function(error, element) { // render error placement each input type var icon = $(element).parent('.input-icon').children('i'); icon.removeclass('fa-check').addclass("fa-warning"); //icon.attr("data-original-title", error.text()).tooltip({ 'container': 'body' }); }, highlight: function(element) { // hightlight error inputs $(element) .closest('.form-group').removeclass("has-success").addclass('has-error'); // set error class control group }, unhighlight: function(element) { // revert change done hightlight }, success: (label, element) => { //$(element).parent().find("p").hide(); var icon = $(element).parent('.input-icon').children('i'); $(element).closest('.form-group').removeclass('has-error').addclass('has-success'); // set success class control group icon.removeclass("fa-warning").addclass("fa-check"); }, }); when form's submit button clicked first time, validates form if click again on submit button goes form submission without validation.
any suggestion appreciated.
prior filling form, on form load, reset form. because taking values cache.
Comments
Post a Comment