Calling refreshFormData on repeater clears them

I have an action that is defined like this:
// app/Filament/Resources/FeedbackResource/Pages/EditFeedback.php
<?php

namespace App\Filament\Resources\FeedbackResource\Pages;

use App\Filament\Resources\FeedbackResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
use Illuminate\Support\Facades\Log;

class EditFeedback extends EditRecord
{
protected static string $resource = FeedbackResource::class;

protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
Actions\Action::make('generate-feedback-ai-sentiment-analysis')
->label('AI Sentiment Analysis')
->action(function () {
Log::info("Generating AI Sentiment Analysis for feedback {$this->record->id}...");
$this->record->performSentimentAnalysisUsingAI();
$this->refreshFormData([
'event_names',
'comments',
'party_size',
]);
}),
];
}
}
// app/Filament/Resources/FeedbackResource/Pages/EditFeedback.php
<?php

namespace App\Filament\Resources\FeedbackResource\Pages;

use App\Filament\Resources\FeedbackResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
use Illuminate\Support\Facades\Log;

class EditFeedback extends EditRecord
{
protected static string $resource = FeedbackResource::class;

protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
Actions\Action::make('generate-feedback-ai-sentiment-analysis')
->label('AI Sentiment Analysis')
->action(function () {
Log::info("Generating AI Sentiment Analysis for feedback {$this->record->id}...");
$this->record->performSentimentAnalysisUsingAI();
$this->refreshFormData([
'event_names',
'comments',
'party_size',
]);
}),
];
}
}
And a form that's like this:
// app/Filament/Resources/FeedbackResource.php
// ...
class FeedbackResource extends Resource
{
// ...
public static function form(Form $form): Form
{
return $form
->schema([
Repeater::make('event_names')
->simple(
TextInput::make('event_name'),
),
Repeater::make('comments')
->simple(
TextInput::make('comment'),
),
TextInput::make('party_size'),
]);
}
}
// app/Filament/Resources/FeedbackResource.php
// ...
class FeedbackResource extends Resource
{
// ...
public static function form(Form $form): Form
{
return $form
->schema([
Repeater::make('event_names')
->simple(
TextInput::make('event_name'),
),
Repeater::make('comments')
->simple(
TextInput::make('comment'),
),
TextInput::make('party_size'),
]);
}
}
And although the party_size field refreshes property, the event_names and comments fields become blank. Am I doing something wrong? I made an example repository here: https://github.com/cloudshipco/filamentphp-repeater-refresh-bug
GitHub
GitHub - cloudshipco/filamentphp-repeater-refresh-bug: A repository...
A repository domonstrating a possible bug in filamentphp/filament - cloudshipco/filamentphp-repeater-refresh-bug
Solution:
use fillForm() instead ```php $this->record->performSentimentAnalysisUsingAI(); $this->fillForm();...
Jump to solution
5 Replies
Solution
LeandroFerreira
LeandroFerreira2mo ago
use fillForm() instead
$this->record->performSentimentAnalysisUsingAI();
$this->fillForm();
$this->record->performSentimentAnalysisUsingAI();
$this->fillForm();
jamespickard
jamespickard2mo ago
That worked but I don't really know why. The only thing I can find about fillForm in the docs is in the context of modals. Is there a bug with refreshFormData? Should I create a GitHub issue?
jamespickard
jamespickard2mo ago
@Leandro Ferreira just checking if you think is worth creating a GitHub issue for? I want to create "next" and "previous" buttons on my form, and I found this solution but it seems unlikely to work if refreshFormData doesn't work for repeater types. https://github.com/filamentphp/filament/discussions/7716
LeandroFerreira
LeandroFerreira2mo ago
Filament
Navigating Filament Pages with Previous and Next Buttons by Leandro...
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
jamespickard
jamespickard2mo ago
Hmm, it looks good and the buttons appear but they don't seem to do anything. I will try to debug it. Ah it works, I forgot to add the trait @Leonardo what do you think about creating a GitHub issue?
Want results from more Discord servers?
Add your server