Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using jQuery to switch to focus a tab with a validation error

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>
like image 310
Robert Parry Avatar asked Aug 12 '13 03:08

Robert Parry


People also ask

How do you validate input field while Focusout?

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.

What is validator addMethod in jQuery?

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.

What is remote validation in jQuery?

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).

What is jQuery validation engine?

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.


1 Answers

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

like image 60
Arun P Johny Avatar answered Sep 22 '22 17:09

Arun P Johny