I don't understand how I can refresh a field

I want to use a HintAction on a field and refresh another. with a codebase like this :
Forms\Components\RichEditor::make('long_description')
->reactive()
->hintAction(
Action::make('getAIDescription')
->label('Récupérer la description depuis AI')
->action(function (Product $record, EditProduct $livewire, Set $set) {
// I TRIED A LOT OF THING
$text = AIService::getDescription($record);
$set('ia_description',$text);
// return $livewire->dispatch('refreshPage');
})
)
->label('Description longue'),

RichEditor::make('ia_description')
->label('Description IA'),
Forms\Components\RichEditor::make('long_description')
->reactive()
->hintAction(
Action::make('getAIDescription')
->label('Récupérer la description depuis AI')
->action(function (Product $record, EditProduct $livewire, Set $set) {
// I TRIED A LOT OF THING
$text = AIService::getDescription($record);
$set('ia_description',$text);
// return $livewire->dispatch('refreshPage');
})
)
->label('Description longue'),

RichEditor::make('ia_description')
->label('Description IA'),
5 Replies
toeknee
toeknee3w ago
you use set, but the problem you have is you are trying to set in a contained action I think you want to call the $livewire get parent record in the action. Then set on that.
DomThomas
DomThomasOP3w ago
Thanks, but I don't understand 🧐
toeknee
toeknee3w ago
Actually looking at https://filamentphp.com/docs/3.x/forms/actions hintActions are not contained. so you should be able to do: $set('ia_description',$text); Can you try changing richeditor to textarea... I am wondering if the editor is not picking up the set
DomThomas
DomThomasOP3w ago
it's the same 😦 I don't understand how I can use $set properly It's ok, if I do this (on the same field) :
RichEditor::make('ia_description')
->label('Description IA')
->columnSpanFull()
->hintAction(
Action::make('generateIA')
->label('Générer')
->icon('heroicon-o-light-bulb')
->action(fn (callable $set, Product $record) => $set('ia_description', AIService::getDescription($record)))
),
RichEditor::make('ia_description')
->label('Description IA')
->columnSpanFull()
->hintAction(
Action::make('generateIA')
->label('Générer')
->icon('heroicon-o-light-bulb')
->action(fn (callable $set, Product $record) => $set('ia_description', AIService::getDescription($record)))
),
toeknee
toeknee3w ago
Interesting, so there must be a container somewhere. I suspect teleport is being used. I'd need to check the source but don't have time. I would just do that then? But render the ID Content in a form model when the action is clicked? and the on submit the action gets the data and sets it?

Did you find this page helpful?