orige-zz / jquery-bootstrap-modal-steps

A lightweight step by step modal for bootstrap
MIT License
30 stars 36 forks source link

Callback issue #15

Closed trix87 closed 6 years ago

trix87 commented 6 years ago

Hello,

I am having an issue with the callback part. The calback that has to be inited only at the 5th step its called on page load automatically.

$(function () {

    var callback1 = function (){
        console.log('A specific callback for step 1!');
    };

    $('#modal-competence-2').modalSteps({
        btnCancelHtml: 'Close',
        btnPreviousHtml: 'Back',
        btnNextHtml: 'Next',
        btnLastStepHtml: 'Save',
        callbacks: {
            '5': callback1()
        }
    });

})

What am i doing wrong so that the 5th step callback to be run when its really the 5th step? Thanks, Trix

orige-zz commented 6 years ago

Hey @trix87, how's going?

The callback is executed while you define the modalSteps:

// What you're doing
$('#modal-competence-2').modalSteps({
        btnCancelHtml: 'Close',
        btnPreviousHtml: 'Back',
        btnNextHtml: 'Next',
        btnLastStepHtml: 'Save',
        callbacks: {
            '5': callback1() // THIS IS THE ERROR. The callback is called when you define the modalSteps
        }
    });

// Just replace to:
$('#modal-competence-2').modalSteps({
        btnCancelHtml: 'Close',
        btnPreviousHtml: 'Back',
        btnNextHtml: 'Next',
        btnLastStepHtml: 'Save',
        callbacks: {
            '5': callback1 // Without ()
        }
    });