F
Filament2y ago
John

Form Wizard save on every next step

I want to save the current step (or the complete form for that matter) every "Next step". I've created a CustomWizard, extending the base Wizard. In my version of this part: https://github.com/filamentphp/forms/blob/2.x/src/Components/Wizard.php#L45 I added this:
$component->getRecord()->update($component->getState());
$component->getRecord()->update($component->getState());
That saves the complete record to the database. Which is cool. But... When I add in a select that's just for filtering another select, $component->getState() misses the ->dehydrated(false) on the "dummy" select. I've noticed that the component uses \Filament\Forms\Components\Concerns\HasState::getState, which doesn't care about dehydration. And EditRecord uses \Filament\Forms\Concerns\HasState::getState, which does. How can I save the Wizard Step form, or the complete Wizard, taking ->dehydrated() into account?
4 Replies
Dan Harrin
Dan Harrin2y ago
on each step maybe try ->afterValidation(callback to save form data)
John
JohnOP2y ago
My Wizard is skippable. I'm not validating after every step, and I don't mind that there are incomplete forms in the db.
Dan Harrin
Dan Harrin2y ago
to take dehydrated() into account, you should get all form data with $livewire->form->getState()
John
JohnOP2y ago
That triggers validation. Which makes total sense, but isn't what I'd like here. I'll investigate some more and think about what I want regarding skippable and validation. Thanks for that $livewire->form->getState() though! Thinking about it, I'll make every db field reactive and save only that field. On Wizard Save the default validation gets triggered. I'll probably add some 'draft' mode to the record until it's fully saved. Thanks @Dan Harrin for the wonderful job on Filament!
Want results from more Discord servers?
Add your server