There is lots of question and answer regarding form validation (client side) for inactive tabs, but however I couldn't do it myself right. I have three tabs on same form and using MVC data annotation, I can validate last tab(active) but it doesn't validate other 2 tabs. Here is my jquery code
var SaveUser = function () {
$("#SaveUserForm").validate({
ignore: ""
});
if (!$("#SaveUserForm").valid()) {
return false;
} else {
var formdata = new FormData($('#SaveUserForm')[0]);
$.ajax({
type: "POST",
url: "@Url.Action("SaveUser", "UserMenu")",
data: formdata,
processData: false,
contentType: false,
success: function(d) {
if (d.Result === 'true') {
alert('success');
} else {
alert('not success');
}
},
error: function() {
}
});
}
return true;
}
- Is there any process that could validate inactive tabs as well?
- How could make error tab focus-able?
Thanks in advance....
Update Html code for tabs:
<ul class="nav nav-tabs">
<li class="active"><a href="#activity" data-toggle="tab">Basic Information</a></li>
<li><a href="#timeline" data-toggle="tab">Login Information</a></li>
<li><a href="#settings" data-toggle="tab">Login Time</a></li>
</ul>
and Tabs content:
<div class="tab-content">
<div class="tab-pane active" id="activity">
//Some input fields
</div>
<div class="tab-pane" id="timeline">
//other input fields
</div>
<div class="tab-pane" id="settings">
//Input fields with
<a href="#" class="btn btn-primary btn-flat" onclick="SaveUser()"><i class="fa fa-floppy-o"></i> Save</a>
</div>
</div>