victorjonsson / jQuery-Form-Validator

[DISCONTINUED] jQuery plugin that makes it easy to validate user input while keeping your HTML markup clean from javascript code.
971 stars 475 forks source link

Tabbed bootstrap form validation #345

Open 1dnmr opened 8 years ago

1dnmr commented 8 years ago

I decided put this question here. It might be useful for somebody else. I have bootstrap tabbed form.

I use function below to validate form after load data. But this code validate only current open tab.

$('#fm').form({
        onLoadSuccess:  function(){     
            $(this).isValid();
        }
    });

I tried to use this to validate on tab change, but this code also not work

$('.nav-tabs').bind('click', function (e) {
    $('#fm').isValid();
});

Can you please suggest solution how I can validate tabbed boostrap form on tab change?

Many thanks!

1dnmr commented 8 years ago

Seems I found the solution:

    $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
         $('#fm').isValid();
    });
KaitaniLabs commented 8 years ago

Thank you so much for this, it was driving me crazy!

I'm using it like this for wizard-style forms:

$('form a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
    $(this).parents("form").isValid();
});

There does seem to be an issue with this when using the toggleDisabled module though. If there are no validation errors on the last tab and your submit button is on there it will enable it even if you have allowed users to skip tabs which have errors on them. Just a heads up.