Validation in each step of the multi-step form
I´m creating a multi-step form using bootstrap and jquery with 4 steps.
But I want that in each step validate the required fields, that is, the button to go to the next step should only work if the required fields are not empty.
But I´m not having success implementing this part of validating each step the required fields. Do you know how to do that?
Jquery:
- $(function(){
-
- // navigation buttons
-
- $('a.nav-link').on('show.bs.tab', function (e) {
- var $target = $(e.target);
- if ($target.parent().hasClass('disabled')) {
- e.preventDefault();
- }
- });
-
- $(".next-step").click(function (e) {
- var $active = $('.nav-pills li a.active');
- $active.parent().next().removeClass('disabled');
- nextTab($active);
- });
-
- $(".prev-step").click(function (e) {
- var $active = $('.nav-pills li a.active');
- prevTab($active);
- });
-
- function nextTab(elem) {
- $(elem).parent().next().find('a.nav-link').click();
- }
- function prevTab(elem) {
- $(elem).parent().prev().find('a.nav-link').click();
- }
- });
HTML