F
Filament5mo ago
Čamap

Reset only one form field into it's default state

Hi! I need to manually reset state of one form input. More specifically inside afterStateUpdated, I want to reset input named "type". Anyone knows how to achieve this? I tried $this->reset('data.type') with no luck, and $this->form->fill() reset's everything..
->afterStateUpdated(function () {
// reset input named "type" into it's default() state
})
->afterStateUpdated(function () {
// reset input named "type" into it's default() state
})
5 Replies
charlie
charlie5mo ago
->afterStateUpdated(function (Set $set) {
// reset input named "type" into it's default() state
$set('type', 'whatever you want');
})
->afterStateUpdated(function (Set $set) {
// reset input named "type" into it's default() state
$set('type', 'whatever you want');
})
Čamap
ČamapOP5mo ago
I need to reset the value, meaning I need it to run the ->default method not just $set @charlie I found this, but it's definitely not the right solution
->afterStateUpdated(function (Set $set) {
$set('type', $this->form->getFlatComponentsByKey()['data.type']->getDefaultState());
})
->afterStateUpdated(function (Set $set) {
$set('type', $this->form->getFlatComponentsByKey()['data.type']->getDefaultState());
})
charlie
charlie5mo ago
Should work:
->afterStateUpdated(function (Set $set, $livewire) {
$set('type', $livewire->getOldFormState('data.type'));
})
->afterStateUpdated(function (Set $set, $livewire) {
$set('type', $livewire->getOldFormState('data.type'));
})
Čamap
ČamapOP5mo ago
What about this?
$set('type', $this->form->getComponent('data.type')->getDefaultState());
$set('type', $this->form->getComponent('data.type')->getDefaultState());
I feel like getOldFormState is not as obvious on firs tsight
toeknee
toeknee5mo ago
You are correct, old will likely be initiated state on boot

Did you find this page helpful?