Argument #1 ($form) must be of type Filament\Forms\Form, Filament\Infolists\Infolist given

It's been a few months since I've done any Filament dev work and I'm back in it and running into this error when trying to add a form to a Page class. I feel like I've run into this before and it was some little quirk that was causing the issue.
use Filament\Forms\Form;
use Filament\Pages\Page;
use Filament\Actions\Action;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Actions\Concerns\InteractsWithActions;

class MyPage extends Page implements HasForms, HasActions
{
use InteractsWithForms, InteractsWithActions;

public ?array $formData= [];

public function form(Form $form): Form
{
return $form->schema([
//form fields
])->statePath('formData');
}
}
use Filament\Forms\Form;
use Filament\Pages\Page;
use Filament\Actions\Action;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Actions\Concerns\InteractsWithActions;

class MyPage extends Page implements HasForms, HasActions
{
use InteractsWithForms, InteractsWithActions;

public ?array $formData= [];

public function form(Form $form): Form
{
return $form->schema([
//form fields
])->statePath('formData');
}
}
in my view I'm doing {{ $this->form }} I feel like I'm doing everything right, but I can't seem to figure out what's going on.
1 Reply
Jon Mason
Jon MasonOP5w ago
The error message is form(): Argument #1 ($form) must be of type Filament\Forms\Form, Filament\Infolists\Infolist given There's not much else going on in this page class. I do have a modal action with a form in it, but I don't recall that interfering with another form outside of an action. I feel like when I've run into this in the past it was because I had multiple forms and wasn't using the getForms() method, but I've tried that as well and still seeing the error. Ok, after all that I started commenting stuff out, and it was because my form field used ->default($this->getDefaultValue) , this fixed it: ->default(fn() => $this->getDefaultValue())

Did you find this page helpful?