2

In the jquery steps, When a user clicks next, I want to make sure all the blanks required are filled, otherwise, an alert will popup. For example, in one steps, there are 6 checkboxes and the user needs to choose at least one, how to add the event listener to next button?

Minhui Su
  • 21
  • 1
  • 2

1 Answers1

1

Please look at Events section here. There is onStepChanging event.

So you can add the event listener like this:

$("#example").steps({
    // options
    // ...
    onStepChanging: function (event, currentIndex, newIndex) {
        if (!validate()) {
            // alert and stop when some validation failed
            alert("Error");
            return false;
        } else {
            // proceed
            return true; 
        }
    }
});
Yurii Semeniuk
  • 933
  • 8
  • 13
  • 1
    Great! As an addition: If you want to handle only clicks on the next button, you could check `if (newIndex > currentIndex) { // do something }` inside the `onStepChanging` function. – Tim Kohlen Jun 24 '19 at 14:56