wdelfuego / nova-wizard

A simple multi-step Wizard tool for Laravel Nova 4
Other
11 stars 5 forks source link

TypeError: Cannot read properties of undefined (reading 'fields') #4

Closed wdelfuego closed 9 months ago

wdelfuego commented 9 months ago

Originally posted by @adrian-schnell in https://github.com/wdelfuego/nova-wizard/issues/3#issuecomment-1805367113

The window remains empty except the navigations. In the console there's this error:

Bildschirmfoto 2023-11-10 um 09 20 09

In the class I copied the demo content:

<?php

namespace App\Nova\Wizard;

use Laravel\Nova\Fields;
use Wdelfuego\NovaWizard\AbstractWizard;

class CreateCommunityWizard extends AbstractWizard
{
    public function wizardViewData(): array
    {
        return [
            'steps' =>
                [
                    'title'  => 'Step 1/2',
                    'fields' => [
                        Fields\Text::make(__('Username'), 'username'),
                        Fields\Text::make(__('Text field'), 'myText'),
                        Fields\Textarea::make(__('Longer text'), 'myLongerText')
                            ->help("You can use Help texts on Nova fields like you're used to"),
                        Fields\Number::make(__('Some number'), 'myNumber')
                            ->rules('required')
                            ->withMeta(['value' => 60])
                            ->min(1)
                            ->step(1),
                    ],
                ],
            [
                'title'  => 'Step 2/2',
                'fields' => [
                    Fields\Text::make(__('Text field 2'), 'myText2'),
                    Fields\Textarea::make(__('Longer text 2'), 'myLongerText2')
                        ->help("You can use Help texts on Nova fields like you're used to"),
                    Fields\Number::make(__('Some number 2'), 'myNumber2')
                        ->rules('required')
                        ->withMeta(['value' => 60])
                        ->min(1)
                        ->step(1),
                ],
            ],
        ];
    }

    public function onSubmit($formData, &$context): bool
    {
        return true;
    }

    public function successViewData($context): array
    {
        return [
            'message' => 'Success! Your Community has been created.',
        ];
    }
}
wdelfuego commented 9 months ago

Thanks for catching that, there was an error in the docs!

The steps entry returned by wizardViewData should contain an array of steps, but the wrapping array was missing from the example code in the documentation.

I've updated the README; please try again with the current code example. Just replace your implementation of wizardViewData() with the updated code example and you should have a working installation.

Thanks a lot for reporting your issues! 🙏