I'm trying to get jQuery to switch to a tab if it finds an error on it. Right now it will find an error but won't go to the tab with the error.
This is the code I currently have
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#Form').validate({
ignore: ".ignore",
invalidHandler: function(){
jQuery("#tabs").tabs("select", jQuery("#Form .input-validation-error").closest(".tab-pane").get(0).id);
}
});
});
jQuery('.Submit').click(function(evt) {
evt.preventDefault();
jQuery('#Form').submit()
});
</script>
The focusout() method in jQuery is used to remove the focus from the selected element. Now we will use focusout() method to validate the input field while focussing out. This method checks whether the input field is empty or not.
validator. addMethod( name, method [, message ] ) Description: Add a custom validation method. It must consist of a name (must be a legal javascript identifier), a javascript based function and a default string message.
I only just found out that the jQuery validation plugins has a validation rule called “remote” which can be used to make an ajax request instead of specifying a custom rule which has an ajax call it in. This will save you heaps of time with those custom validation rules. Basic jQuery Form Validation Tutorial (2mins).
jQuery validation engine is a Javascript plugin aimed at the validation of form fields in the browser (IE 6-8, Chrome, Firefox, Safari, Opera 10). The plugin provides visually appealing prompts that grab user attention on the subject matter. 3k. http://www.position-relative.net/ Tags: form, field, validation, jquery.
Try
jQuery('#userEditForm').validate({
ignore: ".ignore",
invalidHandler: function(e, validator){
if(validator.errorList.length)
$('#tabs a[href="#' + jQuery(validator.errorList[0].element).closest(".tab-pane").attr('id') + '"]').tab('show')
}
});
Demo: Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With