Providing a Closure to a Filament\Pages\Actions\Action causing a livewire failure

Not sure if I'm just being dumb, but when I have a page which has a wizard. I have a custom SubmitFormAction:
protected function getSubmitFormAction(): Action
{
return Action::make('save')
->label('Save Recipients')
->disabled(false)
->submit('save')
->keyBindings(['mod+s']);
}
protected function getSubmitFormAction(): Action
{
return Action::make('save')
->label('Save Recipients')
->disabled(false)
->submit('save')
->keyBindings(['mod+s']);
}
That works But if I change that disabled to being a closure, it fails. Eg:
->disabled(function($state) {
return false;
})
->disabled(function($state) {
return false;
})
Error:
Typed property Filament\Pages\Actions\Action::$livewire must not be accessed before initialization (View: /home/<redacted>/website/vendor/filament/filament/resources/views/components/pages/actions/action.blade.php
Typed property Filament\Pages\Actions\Action::$livewire must not be accessed before initialization (View: /home/<redacted>/website/vendor/filament/filament/resources/views/components/pages/actions/action.blade.php
Am I doing it wrong or is this just not something which is supported?
1 Reply
LeandroFerreira
Would you like to do something like this?
protected function getSubmitFormAction(): Action
{
$disabled = $this->data && $this->data['my_field'] ? false : true;

return Action::make('save')
->label('Save Recipients')
->disabled($disabled)
->submit('save')
->keyBindings(['mod+s']);
}
protected function getSubmitFormAction(): Action
{
$disabled = $this->data && $this->data['my_field'] ? false : true;

return Action::make('save')
->label('Save Recipients')
->disabled($disabled)
->submit('save')
->keyBindings(['mod+s']);
}
Want results from more Discord servers?
Add your server