Grégoire
Grégoire
FFilament
Created by Grégoire on 8/12/2024 in #❓┊help
Looping through multiple Livewire components containing Filament Action crashes Firefox/Safari
No description
11 replies
FFilament
Created by Grégoire on 8/11/2024 in #❓┊help
Handling dispatch events with named parameters in Filament Action
Hi 👋 I'm trying to dispatch a Wire Element Pro event to open a slide-over from within a reusable Filament action. While this works seamlessly when the action is defined within a Livewire component, it doesn't seem to work as expected in a Filament action. Here’s the code that works well in a Livewire component:
public function joinTeamAction()
{
return Action::make('joinTeam')
->action(fn() => $this->dispatch('slide-over.open', component: 'settings.team.switch-team-slide-over'));
}
public function joinTeamAction()
{
return Action::make('joinTeam')
->action(fn() => $this->dispatch('slide-over.open', component: 'settings.team.switch-team-slide-over'));
}
However, when I try to achieve the same in a Filament action extended class, I encounter issues. Specifically, I believe the dispatch method from the CanDispatchEvent trait differs from Livewire's HandlesEvent logic, causing the following problems:
class JoinTeamAction extends Action
{
protected function setUp()
{
parent::setUp();

$this
->action(function () {
// Unknown named parameter $component
$this->dispatch(
'slide-over.open',
component: 'settings.team.switch-team-slide-over'
);

// The event doesn't trigger the slide-over
$this->dispatch(
'slide-over.open',
['component' => 'settings.team.switch-team-slide-over']
);
});
}
}
class JoinTeamAction extends Action
{
protected function setUp()
{
parent::setUp();

$this
->action(function () {
// Unknown named parameter $component
$this->dispatch(
'slide-over.open',
component: 'settings.team.switch-team-slide-over'
);

// The event doesn't trigger the slide-over
$this->dispatch(
'slide-over.open',
['component' => 'settings.team.switch-team-slide-over']
);
});
}
}
- Named Parameters: The first approach using named parameters (component: 'settings.team.switch-team-slide-over') results in an "Unknown named parameter $component" error. - Array Syntax: The 2nd approach using an associative array doesn't throw an error, but it fails to trigger the slide-over event as intended. I also realise that $this->js() is not usable in this context either. Is there a different method or workaround that would allow me to trigger the slide-over event in this context? 🙏
9 replies
FFilament
Created by Grégoire on 7/22/2024 in #❓┊help
Issues with dynamic checkboxlist state in multi-step wizard form
Hi everyone, I am trying to update a CheckboxList depending on the value of a field set in a previous step of a Wizard form. The following code works fine and displays the CheckboxList as expected. However, it seems that all the CheckboxList boxes have the same state, so when I check one box, all the boxes are checked. This seems to be related to how I pass the $get('user_id') value from one step to another. If I hardcode the numeric id instead of the variable, everything works as expected. If I add a debug at the beginning of the second step, I see that the query() is called multiple times, including when the document_id is not set up yet, which is not really what I would expect either. I am really confused as to how to approach the problem. What would you do? EDIT: my message is too long to paste the code, so I shared it in the first reply.
22 replies
FFilament
Created by Grégoire on 6/19/2024 in #❓┊help
Using refreshFormData() in static form methods
Hello everyone, I am a little confused by the "Refreshing form data" part of the documentation. It states that if "you're using actions on an Edit or View resource page, you can refresh data within the main form" which is exactly what I want. The example provided is:
Action::make('approve')
->action(function (Post $record) {
$record->approve();

$this->refreshFormData([
'status',
]);
})
Action::make('approve')
->action(function (Post $record) {
$record->approve();

$this->refreshFormData([
'status',
]);
})
The thing is that a resource page's form method is static, and therefore it is not possible to call $this->refreshFormData() from within the action method. The obvious error (if someone searches by keyword):
Using $this when not in object context
Using $this when not in object context
What am I missing here?
class DocumentResource extends Resource
{
public static function form(Form $form): Form
{
return $form
->schema([
Section::make('AI generated content')
->headerActions([
Action::make('Auto-generate fields')
->icon('heroicon-m-sparkles')
->action(function (Document $record) {
UpdateDocumentMetadata::run($record);
$form->refreshFormData();
})
])
->schema([
// ...
class DocumentResource extends Resource
{
public static function form(Form $form): Form
{
return $form
->schema([
Section::make('AI generated content')
->headerActions([
Action::make('Auto-generate fields')
->icon('heroicon-m-sparkles')
->action(function (Document $record) {
UpdateDocumentMetadata::run($record);
$form->refreshFormData();
})
])
->schema([
// ...
I suppose there is a way to inject the property into the function?
6 replies