Refresh page data from resource form action
I need to call
refreshFormData
(https://filamentphp.com/docs/3.x/panels/pages#refreshing-form-data) from an action within a resource form, but that method is on the page. How can I access the page component from the action method?Solution:Jump to solution
I managed to get this fully working with:
```php
->action(function (array $data, Forms\Components\Repeater $component) {
Chapter::create($data, ...);
$component->clearCachedExistingRecords();...
16 Replies
you can inject
$livewire
Ah ha, thanks! I tried
$page
. Is there a list of everything that can be passed to those closures somewhere?
That works, but refreshFormData
doesn't seem to be doing anything. I'm trying to refresh a relationship (displayed as a repeater). Any ideas?Perfect thanks
could you share the code please?
Sure. Just for context, I want to override the repeaters add action to use a modal that prompts for data and then actually creates the record. It all works perfectly, except I need the repeater to update with the newly added item.
try this please
That works, thanks! But, when you then hit save on the form it attempts to save the chapter again, which fails with a null title column error, and that somehow deletes the row that was previously added... do I need to tell it that item already exists somehow?
hum not sure. I think the correct approach would be to create/update the relationship items using the default submit page action
Yeah I did try that, but I need the drag and drop re-ordering feature. May have to cook up a custom field.
There is a
reorderable
function in Filament tables that you can use.
Yes, you can also create a custom field and manage it as you need.Ah OK, thanks I'll check that out.
It does get even more complicated, because each chapter then has a list of lessons, and ideally I want to end up with a single view where you can add/edit/delete/reorder chapters and lessons 😂
In theory repeater works great for this, I've got the add/edit/delete/reorder working great, it's just syncing the data after the actions that's the issue.
Solution
I managed to get this fully working with:
Thanks again for your help!
much better 👌
And it works perfectly on the nested repeaters as well.