ASP.NET Form Validation in Bootstrap Tabs

2

I have a form in ASP.NET with its content divided into Bootstrap Tabs. However, some of these fields are required (Required) or are type="number" and "email" , if they do not agree, when sending the form will appear a message of HTML5 asking to fill the correct. However, as I'm working with tabs, I can only see the messages if I'm on the tab where it's being displayed.

Is there any way I can, through JavaScript , open the corresponding tab when any of its fields are required or incorrectly filled in?

    
asked by anonymous 19.06.2015 / 16:53

1 answer

2

You can identify the elements with error by "class", as you are using bootstrap I believe the class is "has-error".

Identifying the elements you can identify which tab they belong to by the jQuery's closest function link .

var $elemError = $('.has-error:first');

if($elemError[0]){
    var $tabError = $elemError.closest('.tab-pane');
    var tabErrorId = $tabError.attr('id');  

    $('[href=#' + tabErrorId + ']').tab('show');
}
    
14.08.2015 / 19:42