Action `fillForm` not working inside Repeater

After upgrade to V4 fillForm throws following error when used inside Repeater:
Call to a member function getState() on null {"userId":1,"exception":"[object] (Error(code: 0): Call to a member function getState() on null at /var/www/html/vendor/filament/actions/src/Action.php:498
Call to a member function getState() on null {"userId":1,"exception":"[object] (Error(code: 0): Call to a member function getState() on null at /var/www/html/vendor/filament/actions/src/Action.php:498
Here is a short code example:
$schema
->components([
Repeater::make('stores')
->schema([
TextInput::make('name'),
Actions::make([
Action::make('locations')
->schema([TextInput::make('address')])
->fillForm(fn ($state) => dd($state))
]),
])
]);
$schema
->components([
Repeater::make('stores')
->schema([
TextInput::make('name'),
Actions::make([
Action::make('locations')
->schema([TextInput::make('address')])
->fillForm(fn ($state) => dd($state))
]),
])
]);
Same problem appears when using with Builder Everything works fine when action is used outside Repeater, for example:
// Working example
$schema
->components([
/** Repeater::make('stores') */
/** ->schema([ */
TextInput::make('name'),
Actions::make([
Action::make('locations')
->schema([TextInput::make('address')])
->fillForm(fn ($state) => dd($state))
]),
/** ]) */
]);
// Working example
$schema
->components([
/** Repeater::make('stores') */
/** ->schema([ */
TextInput::make('name'),
Actions::make([
Action::make('locations')
->schema([TextInput::make('address')])
->fillForm(fn ($state) => dd($state))
]),
/** ]) */
]);
Solution:
Found a solution. Replaced fillForm with mountUsing. ```php Action::make('locations') ->schema([TextInput::make('address')]) ->mountUsing(static function (Schema $schema, $state): void {...
Jump to solution
2 Replies
Solution
23sergej
23sergej2mo ago
Found a solution. Replaced fillForm with mountUsing.
Action::make('locations')
->schema([TextInput::make('address')])
->mountUsing(static function (Schema $schema, $state): void {
$schema->fill([
'address' => $state['valueFromState'] ?? '',
]);
})
// ->fillForm(fn ($state) => dd($state))
Action::make('locations')
->schema([TextInput::make('address')])
->mountUsing(static function (Schema $schema, $state): void {
$schema->fill([
'address' => $state['valueFromState'] ?? '',
]);
})
// ->fillForm(fn ($state) => dd($state))
Asmit
Asmit2mo ago
Another Approach: If you use relate Records
Action::make('update')
->mountUsing(function ($record, Schema $schema, Component $component) {
$relatedRecord = $component->getRecord();
// OR
$relatedRecord = $component->getContainer()->getParentComponent()->getContainer()->getRecord();
});
Action::make('update')
->mountUsing(function ($record, Schema $schema, Component $component) {
$relatedRecord = $component->getRecord();
// OR
$relatedRecord = $component->getContainer()->getParentComponent()->getContainer()->getRecord();
});

Did you find this page helpful?