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 use values from previous step? #10

Closed patrickkusebauch closed 3 years ago

patrickkusebauch commented 4 years ago

Hello, have used the template for latte used in the quickstart.

<div n:wizard="wizard">
    <ul n:if="!$wizard->isSuccess()">
        <li n:foreach="$wizard->steps as $step" n:class="$wizard->isDisabled($step) ? disabled, $wizard->isActive($step) ? active">
            <a n:tag-if="$wizard->useLink($step)" n:href="changeStep! $step">{$step}</a>
        </li>
    </ul>

    {step 1}
        {control $form}
    {/step}

    {step 2}
        {control $form}
    {/step}

    {step success}
        Registration was successful
    {/step}
</div>

However, whenever I reference a value from a previous step in the Component like this:

            protected function createStep2(): Form
            {
                $values = $this->getValues();
                $form   = $this->createForm();

                if($values->seasonDesc === 'personal') {
                    //conditional form based on values from the first step
                   }
            }

I get Notice: Undefined property: Nette\Utils\ArrayHash::{$nameOfProperty} even though I know the property should exist since it was created in the previous step.

This is the whole point of a wizard for me, that I can change the next step's form base on the values from the previous step. So is there any canonical way to do this other than always calling $values->offsetExists('seasonDesc')?

MartkCz commented 4 years ago

I'm working on reworking the wizard to fix #10 #9

MartkCz commented 4 years ago

11

bdump($this->getRawValues()[1]['seasonDesc']);

Please test PR