F
Filament17mo 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 Boivin17mo ago
Can you share what you have? It would help to offer an alternative...
Saade
Saade17mo ago
you could $this->form->fill($this->record->attributesToArray()) but make sure your're not exposing any sensitive data to the frontend
KeyMe
KeyMeOP17mo 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
Saade17mo ago
$this->record->update($data)?
KeyMe
KeyMeOP17mo ago
lol thanks, i felt dumb for not figuring that refreshing the form doesnt seem to work the same tho
Saade
Saade17mo ago
you can $this->form->fill($data) too, but the form should be already refreshed with the data you've typed in, no?
KeyMe
KeyMeOP17mo ago
not if i do $this->refreshFormData($data) no
Saade
Saade17mo ago
i mean, why do you need to refresh the form when the information is already updated?
KeyMe
KeyMeOP17mo 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
sweetplum14mo 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
KeyMeOP14mo ago
you can use $this->fillForm() in the modal action() closure
sweetplum
sweetplum14mo ago
thanks. but this didn't work for my case.
Want results from more Discord servers?
Add your server