0
I use the tab of bootstrap and the required of dataannotations,
but the following happens, not to know the required fields, when it is not in the tab of him, for example, I’m in tab 1, and I conclude, but in the 2 fields with required are not filled, can not know, I would like to go to tab where the fields with required were not completed.
I tried this code both on submit and with the click of button, but it didn’t work:
$('#btnConcluir').click(function () {
$('input:invalid').each(function () {
// Find the tab-pane that this element is inside, and get the id
var $closest = $(this).closest('.tab-pane');
var id = $closest.attr('id');
// Find the link that corresponds to the pane and have it show
$('.nav a[href="#' + id + '"]').tab('show');
// Only want to do it once
return false;
});
});
I tried this one too:
$('#btnConcluir').click(function () {
console.log('entrou');
$(':required:invalid', '#FornecedorNovo').each(function () {
var id = $('.tab-pane').find(':required:invalid').closest('.tab-pane').attr('id');
$('.nav a[href="#' + id + '"]').tab('show');
});
});
Mariana, the
:invalidworks with fields where you have the attributerequired. I have no knowledge about this resource you are using, thedataannotations. If only for therequiredHTML5 that your code should work perfectly, and detail: that loopeachnot even necessary, just see if$('input:invalid', '#FornecedorNovo').lengthis true or false that it already finds the field empty.– Sam
@Sam I’m going to do a test this way, have some idea of some way that I can verify?
– Mariana
@sam I did the test and it didn’t work, the console it only validates the fields of the selected tab, and not of all.
– Mariana