F
Filament4mo ago
morty

Building my first table action and it's doing weird behaviour using Spatie Tags plugin.

I have a table on my resource that I'm adding a manage tags action to. This is using the filament spatie tags plugin. Two things are happening that I wasn't expecting. One, the $data array is empty on submit for some reason. Two, there is nothing in the action method except debugging lines but for some reason the tag is being applied to the resource anyway. Is there some magic happening behind the scenes with the plugin? Here is my code on the table:
->actions([
Action::make('tags')
->label('Manage tags')
->icon('heroicon-o-plus-circle')
->slideOver()
->modalWidth(MaxWidth::Medium)
->form([
SpatieTagsInput::make('tags')
->type('crm.account')
->required(),
])
->action(function (array $data, Account $account) {
ray()->clearAll();
ray($data, $account);
}),
->actions([
Action::make('tags')
->label('Manage tags')
->icon('heroicon-o-plus-circle')
->slideOver()
->modalWidth(MaxWidth::Medium)
->form([
SpatieTagsInput::make('tags')
->type('crm.account')
->required(),
])
->action(function (array $data, Account $account) {
ray()->clearAll();
ray($data, $account);
}),
1 Reply
morty
morty4mo ago
I noticed the documentation states the following:
The field will automatically load and save its tags to your model. To set this functionality up, you must also follow the instructions set out in the field relationships section. If you're using the Panel Builder, you can skip this step.
This isn't ideal in this case though. I noticed that if there are other fields on the form and you hit a validation error, the tags are still persisted even though the form hasn't been correctly submitted yet. I'm going to look at an alternative for now but if anyone knows if I can turn off the automatic saving form specific, please let me know.