Calling refreshFormData on repeat fields clears them
Package
filament/filament
Package Version
v3.2.110
Laravel Version
v11.22.0
Livewire Version
v3.5.6
PHP Version
PHP 8.3.8
Problem description
I called refreshFormData with fields fields that are defined using Repeater::make and it cleared them.
Expected behavior
I expected the fields to be updated with their latest values.
Steps to reproduce
- Create a simple Repeater field in your Resource:
Repeater::make('comments')
->simple(
TextInput::make('comment'),
),
- Add an action to
getHeaderActionsin the EditRecord:
Actions\Action::make('update comments')
->action(function () {
// Modify comments
$this->record->comments = ['foo', 'bar'];
$this->record->save();
$this->refreshFormData([
'comments',
]);
}),
- Observe that the comments repeater fields are cleared instead of updated with new values.
Reproduction repository (issue will be closed if this is not valid)
https://github.com/cloudshipco/filamentphp-repeater-refresh-bug
Relevant log output
n/a
Donate 💰 to fund this issue
- You can donate funding to this issue. We receive the money once the issue is completed & confirmed by you.
- 100% of the funding will be distributed between the Filament core team to run all aspects of the project.
- Thank you in advance for helping us make maintenance sustainable!
In that scenario I would typically use $this->fillForm() instead of $this->refreshFormData().
Otherwise, looking at your form schema, the refreshFormData would typically look for an array of comments with each having a comment key corresponding to the name of the TextInput. So this change should work:
- $this->record->comments = ['foo', 'bar'];
+ $this->record->comments = [['comment' => 'foo'], ['comment' => 'bar']];
@yuters, simple repeaters do actually use a flat array to store items, so this might in fact be a bug.
@zepfietje yep could probably be improved for simple repeaters. Just suggesting some workarounds.
Should be fixed by #15514