How to prefill data after "createAnother" action?
Hey, just wanna maintain some inputs prefilled when I hit the "createAnother" button. I'm trying some Action methods but can't get it :/
5 Replies
you just need default() values on the fields
request() wont work, this is not a controller.
store the fields in the session or something before they are saved and then access from there
hm yep it works with session flash, but how can I store the session only when "createAnother" event. I've tried using "afterCreate" method
you could override createAnother(), store the data in session, and then
parent::createAnother()
Allright it works!
Just added the session store after:
`
Thanks mate!
Hey, just wanna maintain some inputs prefilled when I hit the "createAnother" button. I'm trying some Action methods but can't get it :/ class CreateQuestion extends CreateRecord
{
protected static string $resource = QuestionResource::class;
public function getTitle(): string|Htmlable
{
return __('models/question.action.create');
}
protected function getHeaderActions(): array
{
return [
$this->getCreateFormAction()
->submit(null)
->action('create'),
$this->getCreateAnotherFormAction()
->submit(null)
->action(fn () => $this->createAnother()),
$this->getCancelFormAction()
->submit(null)
->action('cancel'),
];
}
protected function getFormActions(): array
{
return [];
}
public function createAnother(): void
{
session()->flash('dataFill', [
'purpose' => $this->data['purpose'],
'books' => $this->data['books'],
]);
parent::createAnother();
}