Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling refreshFormData on repeat fields clears them #14222

Open
euoia opened this issue Sep 12, 2024 · 1 comment
Open

Calling refreshFormData on repeat fields clears them #14222

euoia opened this issue Sep 12, 2024 · 1 comment
Labels

Comments

@euoia
Copy link

euoia commented Sep 12, 2024

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

  1. Create a simple Repeater field in your Resource:
                Repeater::make('comments')
                    ->simple(
                        TextInput::make('comment'),
                    ),
  1. Add an action to getHeaderActions in the EditRecord:
            Actions\Action::make('update comments')
                ->action(function () {
                    // Modify comments
                    $this->record->comments = ['foo', 'bar'];
                    $this->record->save();

                    $this->refreshFormData([
                        'comments',
                    ]);
                }),
  1. 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!
Fund with Polar
@euoia euoia added bug Something isn't working medium priority unconfirmed labels Sep 12, 2024
@yuters
Copy link
Contributor

yuters commented Sep 13, 2024

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']];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Todo
Development

No branches or pull requests

2 participants