contributte / forms-wizard

:tophat: Easy to use step-by-step form for Nette Framework
https://contributte.org/packages/contributte/forms-wizard.html
MIT License
15 stars 10 forks source link

Documentation - How to skip a step? #9

Closed patrickkusebauch closed 3 years ago

patrickkusebauch commented 4 years ago

I think it is self-explanatory. I am looking for a way to skip a step based on the values from a previous step.

I tried this naive solution, but to no avail:

            protected function createStep2(): Form
            {
                $values = $this->getValues();
                if(isset($values['seasonDesc']) && $values['seasonDesc'] === 'personal') {
                    $this->setStep($this->getCurrentStep() + 1);
                    return $this->create(); //Since I have to return a Form
                }
            }

However this results in Component 'step3' already has a parent

MartkCz commented 4 years ago

11

$this->skipStepIf(2, function (array $values): bool {
    return isset($values[1]) && $values[1]['seasonDesc'] === 'personal';
});

If first step is submitted with 'seasonDesc' === 'personal', second step is skipped and third step is rendered