#refreshFormData in afterSave() function
21 messages · Page 1 of 1 (latest)
Try similar to thishttps://stackoverflow.com/questions/74527583/filamentphp-ho-to-refresh-re-calculate-the-count-value-on-header
thanks mate
You could calcualte it in a view field or similar though on the fly based on changes in the form
@dire epoch mmm debugging the code, the problem is slightly different
the function refresh the field...but not take the last value save in db but the previous...
(consider that the field in db is virtual... if i refresh page the result is correct)
protected function afterSave(): void
{
$this->refreshFormData([
'calorie_calc',
]);
}
protected function afterSave(): void
{
$this->refreshFormData([
'calorie_calc' => $this->record->refresh()->calorie_calc
]);
}
How about this ?
Where does the calorie_calc value come from? why are you trying to update it after save?
Ok.. just use $this->form->fill($this->record->refresh()->toArray())
now work 🙂 ..but why not work with refreshFormData?
Is this a custom page?
i try this....and not work
$this->refreshFormData([
'calorie_calc' => 13
]);
no simple EditRecord
So viewRecord and EditRecord has the refreshFormData which does
public function refreshFormData(array $attributes): void
{
$data = [
...$this->data,
...Arr::only($this->getRecord()->attributesToArray(), $attributes),
];
$this->form->fill($data);
}
So if you pass in the correct attribute it should trump it...
try
$this->refreshFormData($this->record->refresh()->toArray())
Method Filament\Forms\Form::refreshFormData does not exist.
Sorry updated
$this->form->fill($this->record->refresh()->toArray()); this work correctly
I just wanted to understand if refreshFormData couldn't be used
So it should be used can can be, it's defined It could be that it's too late in the cycle. But either way, if the fill works and that's all refresh does... then win win!