Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Callback on beforeNext #36

Open
francesco-loreti opened this issue Jul 17, 2019 · 1 comment
Open

Callback on beforeNext #36

francesco-loreti opened this issue Jul 17, 2019 · 1 comment

Comments

@francesco-loreti
Copy link

Is it possible block nextStep? I have tried with "return false;" in beforeNext event but not work.
Thanks!

@masiref
Copy link

masiref commented Mar 26, 2020

Hi @francesco-loreti,

It's possible to block a step on condition, it's a bit tricky but it works. You'll find below how I figured it out.

let steps = bulmaSteps.attach('.steps', {
    ...

    beforeNext: id => {
        switch(id) {
            // first step
            case 0:
                // must return an array of errors
                // if empty it goes to next step
                // if not empty it triggers onError with the first item of array
                return validateFirstStep();
            
            // second step
            case 1:
                ...
        }
    },
    onError: error => {
        console.log(error);
    }
});

const validateFirstStep = () => {
    let errors = [];
    ...

    if (validationRuleNotVerified) {
        errors.push('Validation rule not verified');
    }
    if (otherValidationRuleNotVerified) {
        errors.push('Other validation rule not verified');
    }
    return errors;
};

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants