F
Filament11mo ago
Wiebe

Reset form data in action

I've got an action with a form, within that action i've got another action, with that action i want to reset the form data but it doesnt seem to do anything.
protected function setUp(): void {
parent::setUp();

$this->modalCancelAction(false)
->modalSubmitAction(false)
->extraModalFooterActions([
Action::make('next')
->action(function($record){
$this->resetFormData();
})
]);

$this->mountUsing(function (ComponentContainer $form, ManufacturingOrder $order){
$form->fill([
'status' => $order->status,
]);
});

$this->form([
Select::make('status')->options([
'open' => 'Open',
'finished' => 'Finished',
})->afterStateUpdated(function ($record, $state) {
$record->update(['status' => $state])
})->reactive()
])

->action(function($data, $record){
dd($data, $record);
});
}
protected function setUp(): void {
parent::setUp();

$this->modalCancelAction(false)
->modalSubmitAction(false)
->extraModalFooterActions([
Action::make('next')
->action(function($record){
$this->resetFormData();
})
]);

$this->mountUsing(function (ComponentContainer $form, ManufacturingOrder $order){
$form->fill([
'status' => $order->status,
]);
});

$this->form([
Select::make('status')->options([
'open' => 'Open',
'finished' => 'Finished',
})->afterStateUpdated(function ($record, $state) {
$record->update(['status' => $state])
})->reactive()
])

->action(function($data, $record){
dd($data, $record);
});
}
5 Replies
toeknee
toeknee11mo ago
$this will only reset that actions form, you need to reset the parent data?
Wiebe
Wiebe11mo ago
yes @toeknee Do you have a solution for this?
toeknee
toeknee11mo ago
I am not sure tbh... you could try: Closure $get, $set and then: $set('../', [])
Wiebe
Wiebe11mo ago
Doenst work
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
->action(function(Set $set, $record){
$set('../', []);
})
->action(function(Set $set, $record){
$set('../', []);
})
toeknee
toeknee11mo ago
->action(function(Closure $set, $record){ $set('../', []); }) If it not closure?