Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for bug #12602 #12605

Closed
wants to merge 1 commit into from
Closed

Conversation

dmitry-udod
Copy link
Contributor

Description

Fix for bug #12602

Screencast.2024-05-03.16.06.32.mp4

Visual changes

Nope

Functional changes

  • Code style has been fixed by running the composer cs command.
  • Changes have been tested to not break existing functionality.
  • Documentation is up-to-date.

@danharrin
Copy link
Member

I don't think this is a problem specific to wizards. It happens whenever a dynamic schema is involved, and my advice is usually to use afterStateUpdated() on the component that determines the schema to $set() the field values for the new fields. I do feel a bit weird filling the defaults after the form is first loaded, it could be unexpected behaviour.

Gonna need to leave this open while I consider it

@danharrin danharrin added the bug Something isn't working label May 3, 2024
@danharrin danharrin self-assigned this May 3, 2024
@danharrin danharrin added this to the v3 milestone May 3, 2024
@dmitry-udod
Copy link
Contributor Author

@danharrin Hi! Sure. Just FYI, the problem here is that without applying default values for next step fields, we don't have this data at all. Please check the video.

Screencast.2024-05-03.16.28.14.mp4

@danharrin
Copy link
Member

Yeah, so it's the same problem as something like this:

TextInput::make('test'),
Group::make(function ($get) {
    if ($get('test') === 'foo') {
        return [CheckboxList::make('test2')->options(['one' => 'One', 'two' => 'Two'])];
    }

    return [];
}),

Which is solved by:

TextInput::make('test')
    ->afterStateUpdated(fn ($set, $state) => ($state === 'foo') ?
        $set('test2', []) :
        null
    ),
Group::make(function ($get) {
    if ($get('test') === 'foo') {
        return [CheckboxList::make('test2')->options(['one' => 'One', 'two' => 'Two'])];
    }

    return [];
}),

@danharrin
Copy link
Member

This solution is actually documented, so closing this

@danharrin danharrin closed this May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
2 participants