F
Filament6d ago
SOIX

Share state between nested modal

Hello, is it possible to share state between nested modals, my solution almost works but when i try to re-open child modal I cannot get parent one values to set as default:
Forms\Components\Section::make('Heading')
->collapsible()
->schema([
Forms\Components\Hidden::make('heading.color'), // sadly I need to have this, otherwise $set('heading.color', $data['color']); would be inside child modal only
Forms\Components\TextInput::make("heading.text")
->hiddenLabel()
->required()
->columnSpan(5),

Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('settings')
->form([
Forms\Components\ColorPicker::make('color')
->default(fn (Get $get) => $get('heading.color')),
])
->action(function (Set $set, Get $get, $data) {
$set('heading.color', $data['color']);
})
])
->columnSpan(1)

])->columns(6),
Forms\Components\Section::make('Heading')
->collapsible()
->schema([
Forms\Components\Hidden::make('heading.color'), // sadly I need to have this, otherwise $set('heading.color', $data['color']); would be inside child modal only
Forms\Components\TextInput::make("heading.text")
->hiddenLabel()
->required()
->columnSpan(5),

Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('settings')
->form([
Forms\Components\ColorPicker::make('color')
->default(fn (Get $get) => $get('heading.color')),
])
->action(function (Set $set, Get $get, $data) {
$set('heading.color', $data['color']);
})
])
->columnSpan(1)

])->columns(6),
Solution:
This should work, in the action modal, use ->form([...])->mountUsing(function (Form $form, Forms\Get $get) { $form->fill([ 'color' => $get('heading.color') ?? 'something' ]); })...
Jump to solution
3 Replies
SOIX
SOIX6d ago
This would be one way of doing it, very hacky:
->default(fn ($livewire) => $livewire->mountedFormComponentActionsData[0]['heading']['color']),
->default(fn ($livewire) => $livewire->mountedFormComponentActionsData[0]['heading']['color']),
Anything else?
Solution
Cristina
Cristina5d ago
This should work, in the action modal, use ->form([...])->mountUsing(function (Form $form, Forms\Get $get) { $form->fill([ 'color' => $get('heading.color') ?? 'something' ]); })
SOIX
SOIX5d ago
Yes, this works very well! Thanks madam!
Want results from more Discord servers?
Add your server