$livewire->form->fill() doesn't work when using slideOver()
I've been following Kevin McKee's excellent "Rapid Laravel Apps with Filament" Laracast but run into an issue when trying to use a factory to fill a form (for testing purposes).
When my resource ("Campaign") has a dedicated CreateCampaign route/page, I'm able to add an action to the form as follows:
and this works great. However, I'd prefer to use the slideOver() so I comment out
'create' => Pages\CreateCampaign::route('/create'),
in the getPages()
function of the campaign resource and add ->slideOver()
to the getHeaderActions
of the ListCampaigns
file (no other changes made).
I then get the following error:
Filament\Resources\Pages\ListRecords::form(): Argument #1 ($form) must be of type Filament\Forms\Form, Filament\Infolists\Infolist given, called in /Users/joe/Projects/test_system/vendor/filament/infolists/src/Concerns/InteractsWithInfolists.php on line 56It looks like, when using a slideOver, $livewire is the ListCampaign component rather than the CreateCampaign page so the form is not accessible through $livewire->form. I'm sure there is an easy workaround but I'm pretty new to all this. Thanks 🙂
31 Replies
A slideOver would indicate a modal create action, but you’re telling the resource that the create action is a route. Not sure what you’re trying to do.
It’s either a route or it isn’t. It can’t be both.
I started with it as a route to check that the "Insert test data" button was working (it was) but then removed the route and switched to the slideOver which is where the error started occurring.
The
The
Actions...
snippet above is part of the form definition of the CampaignResource
so I thought that the $livewire reference would be the form but it seems to be the ViewCampaigns
component (which is the one that has the modal-triggering button on it).
I'm just looking for a way to fill a slideOver form 🙂 given that $livewire->form doesn't seem to workOk, but slideOver isn’t a route, but your resource is defining a route. It’s 2 different things. Also, the resource isn’t a livewire component.
The resource is just a class that the view, edit, create and list livewire components can reference.
"but your resource is defining a route" - in what way? I thought removing the
create
route from getPages()
was sufficient if I planned on using a modal?What is the actual code of your header action and what classes are you including it on?
Also, form()->fill() only works in mount of a livewire component.
So for actual actions there is a ->fillForm() modifier that achieves the same thing. Just not sure of the use case of what you are actually trying to achieve.
This is my
app/Filament/Admin/Resources/CampaignResource.php
https://gist.github.com/joeczucha/4512e9c3726141d64ae66f9e723080f0
line 74+Ok, you can’t fill the form after initialization. At the point you should be using $set to modify the form data.
Fill form only applies to the form initialization which happens on mount.
ah I see. I had looked at $set but could only find examples of doing one field at a time rather than the whole form
Yeah, setting the entire form based on a field doesn’t make sense to me. I could be wrong though.
the use case that I have is trying to get the button on this form ("Insert test data") to populate the form with my factory test data

and it works in this layout.
but not in this one
which is what we use everywhere

I'm pretty sure
$this->form->fill()
should be enoughthanks Matthew, I tried a few combinations of $this, $self, etc.
Your example gives me this error:
Using $this when not in object context
Can I see the code?
You can't put $this in static functions 😅
line 84 is where I'm calling it
I see line 84 has $livewire, that doesn't work also, right?
so when I have a dedicated CreateCampaign route, the $livewire in line 84 allows me to do $livewire->form->fill() and it works. but when I use a slideOver the $livewire reference is the ViewCampaign component (i.e. the page with the button on). so I guess I need a way to access the form via the ViewCampaign page.
Very interesting...
A route doesn’t work in a modal.
so no way to fill the form, except for using $set?
It’s not that you can’t fill a form it’s that how you’re trying to do it doesn’t make sense to me because it’s too late in the life cycle of the request.
okay I think I understand. so what you're saying is that outputting a form in a modal vs it's own route significantly changes how it's rendered and in the case of the modal it's then too late to create an action to fill it?
Kinda. Hard to explain. Depends on several factors.
It’s all about the lifecycle
Either way you can’t depend on a route for create but also expect create to work in a modal at the same time.
It just doesn’t work that way.
And that not a filament issue.
Can I just ask which aspect of the code suggests that I'm trying to use a route AND use a modal? If I've removed the Create line from getPages() array does that not disable the route?
Maybe a caching issue.
I'm still no closer to getting this working, if anyone else has any thoughts 🙂
amazing, thank you so much @Leandro Ferreira