Why doesn't my Filament form populate on load?
Sorry for the beginners question.
I thought $this->form->fill would cause my TextInput field to get prepopulated. But it doesn't. Here's my Livewire Form php class.
<?php
declare(strict_types=1);
namespace App\Livewire;
use App\Models\Legacy\Individual;
use Livewire\Component;
use Filament\Forms\Components\TextInput;
use Filament\Forms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Components\Section;
use Symfony\Component\HttpFoundation\Request;
class InvestorIndividualForm extends Component implements HasForms
{
use InteractsWithForms;
public function mount(Request $request)
{
$this->form->fill(['firstname' => 'Bob']);
}
protected function getFormSchema(): array
{
return [TextInput::make('firstname')];
}
}
Solution:Jump to solution
It's set when you
fill()
the form. Your component would look like this
```php
<?php
...6 Replies
That looks good
Any error in your browser console?
Try adjusting your mount:
public function mount(Post $post): void
{
$this->form->fill($post->toArray());
}
As an example as per:
https://filamentphp.com/docs/3.x/forms/adding-a-form-to-a-livewire-component
you need a
$firstname
public property.
or you can use the v3 way of declaring forms
so either add
public string $firstname = ''
to your component
or
@urbycozI'd like to do it the v3 way ideally. So where does the $data property get set?
Solution
It's set when you
fill()
the form. Your component would look like this
That's perfect. Thanks so much