F
Filament12mo ago
KeyMe

Action modal form with many field to prefill

I have an action with modal form, initially i follow the documentation example to fill the form with default data, but now theres too many fields in the form, is there another way that gives less redundancy?
12 Replies
Patrick Boivin
Patrick Boivin12mo ago
Can you share what you have? It would help to offer an alternative...
Saade
Saade12mo ago
you could $this->form->fill($this->record->attributesToArray()) but make sure your're not exposing any sensitive data to the frontend
KeyMe
KeyMe12mo ago
thanks, that works well, and how about for saving the updated data? for example currently i do it like so
->action(function (array $data): void {
$this->record->update(['company_name' => $data['company_name']]);
$this->refreshFormData(['company_name']);
})
->action(function (array $data): void {
$this->record->update(['company_name' => $data['company_name']]);
$this->refreshFormData(['company_name']);
})
Saade
Saade12mo ago
$this->record->update($data)?
KeyMe
KeyMe12mo ago
lol thanks, i felt dumb for not figuring that refreshing the form doesnt seem to work the same tho
Saade
Saade12mo ago
you can $this->form->fill($data) too, but the form should be already refreshed with the data you've typed in, no?
KeyMe
KeyMe12mo ago
not if i do $this->refreshFormData($data) no
Saade
Saade12mo ago
i mean, why do you need to refresh the form when the information is already updated?
KeyMe
KeyMe12mo ago
idk ig bcs it doesnt look good to the eye cus when the modal is closed the view/page isnt automatically refreshed lol
sweetplum
sweetplum9mo ago
Hi, have you found a way to automatically refresh form data after the Modal data is updated and closed? On my main form, I have a modal to update a related record, but the related record is not refreshed after the modal is done. Thanks!
KeyMe
KeyMe9mo ago
you can use $this->fillForm() in the modal action() closure
sweetplum
sweetplum9mo ago
thanks. but this didn't work for my case.