Last active
August 29, 2015 14:04
-
-
Save denieler/143f3509e4bc66c82494 to your computer and use it in GitHub Desktop.
JQuery event handler on validation form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var settings = $.data($('form')[0], 'validator').settings; | |
$("form").bind("invalid-form.validate", function (form,validator) { | |
var errors = validator.numberOfInvalids(); | |
var message = "Please fix" + errors + " errors."; | |
for (var x=0;x<validator.errorList.length;x++) | |
{ | |
message += "<br/>\u25CF " + validator.errorList[x].message + 'Element:' + $(validator.errorList[x].element).attr('name'); | |
} | |
console.log(message); | |
// $("#errorList").html(message); | |
// $("#errorList").slideDown('fast'); | |
}); | |
settings.submitHandler = function (form) { | |
if (confirm("Are you sure you wish to submit")) | |
form.submit(); | |
}; | |
//------------------------------------------------- | |
$.validator.setDefaults({ | |
highlight: function (element) { | |
console.log('highlight'); | |
}, | |
unhighlight: function (element) { | |
console.log('unhighlight'); | |
} | |
}); | |
//------------------------------------------------- | |
var valOpts = $.data($('form')[0], 'validator').settings; //we've got jQuery.validation settings woohoo! | |
var baseError = valOpts.errorPlacement; | |
valOpts.errorPlacement = function (error, input) { | |
console.log(error.text()); //error is the $('<span>...</span>') | |
baseError(error, input); //removing this breaks form validation | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment