How to set a form value in a resource from a custom action

I have an action that contains a conversation_report_gpt textarea, I would like to update the value of this field after clicking on an action button.
1 Reply
Patrick1989
Patrick19894mo ago
return [
Actions\Action::make('gespreksverslag_herschrijven')
->label('Gespreksverslag herschrijven')
->icon('heroicon-o-pencil')
->fillForm(function($livewire){
$formData = $livewire->form->getRawState();
return [
'conversation_report_original' => $formData['conversation_report_original'],
'prompt' => static::$prompt,
];
})
->form([
Section::make()
->columns(2)
->schema([
TextArea::make('prompt')
->rows(5)
->columnSpanFull(),
Textarea::make('conversation_report_original')
->label('Gespreksverslag origineel')
->rows(10)
->required(),
Textarea::make('conversation_report_gpt')
->reactive()
->label('Gespreksverslag GPT')
->rows(10),
]),
])->action(function(array $data, $arguments, $livewire){
if($arguments['rewrite'] ?? false){

}
})->extraModalFooterActions(function(Action $action): array{
return [
$action->makeModalSubmitAction('Herschrijven', arguments: ['rewrite' => true])
];
}),
...parent::getFormActions(),
];
return [
Actions\Action::make('gespreksverslag_herschrijven')
->label('Gespreksverslag herschrijven')
->icon('heroicon-o-pencil')
->fillForm(function($livewire){
$formData = $livewire->form->getRawState();
return [
'conversation_report_original' => $formData['conversation_report_original'],
'prompt' => static::$prompt,
];
})
->form([
Section::make()
->columns(2)
->schema([
TextArea::make('prompt')
->rows(5)
->columnSpanFull(),
Textarea::make('conversation_report_original')
->label('Gespreksverslag origineel')
->rows(10)
->required(),
Textarea::make('conversation_report_gpt')
->reactive()
->label('Gespreksverslag GPT')
->rows(10),
]),
])->action(function(array $data, $arguments, $livewire){
if($arguments['rewrite'] ?? false){

}
})->extraModalFooterActions(function(Action $action): array{
return [
$action->makeModalSubmitAction('Herschrijven', arguments: ['rewrite' => true])
];
}),
...parent::getFormActions(),
];
That's my action. When the rewrite action is done I want to update the conversation_report_gpt with the new value and prevent the modal from closing i can use halt() ? i think to prevent it from closing, but I'm not sure how to update the form value. I tried this:
)->action(function(Set $set, $arguments){
if($arguments['rewrite'] ?? false){
// i want to update the resource form with the new text here

$set('conversation_report_gpt', 'testing');

$this->halt();
}
})
)->action(function(Set $set, $arguments){
if($arguments['rewrite'] ?? false){
// i want to update the resource form with the new text here

$set('conversation_report_gpt', 'testing');

$this->halt();
}
})
But that gives me the following error:
Typed property Filament\Forms\Components\Component::$container must not be accessed before initialization
Typed property Filament\Forms\Components\Component::$container must not be accessed before initialization
In short, this is what i want
TextInput::make('conversation_report_original')
->label('Gespreksverslag origineel')
->required()
->suffixAction(
ActionsAction::make('Herschrijven')
->icon('heroicon-o-pencil')
->action(function(Set $set){
$set('conversation_report_gpt', 'cheese');
$this->halt();
})
)
,
TextInput::make('conversation_report_original')
->label('Gespreksverslag origineel')
->required()
->suffixAction(
ActionsAction::make('Herschrijven')
->icon('heroicon-o-pencil')
->action(function(Set $set){
$set('conversation_report_gpt', 'cheese');
$this->halt();
})
)
,
but with a textarea instead