Form builder - File fields?
How are we handling files in the form builder? When save to json it won't repopulate as an array as it expects a string. Usually we cast on the model, but can't when we don't know the fields
10 Replies
Do you have an example of your issue?
Stored with 'data' => $this->data
Then we fill with the data from the submission when reviewing / editing with $this->form->fill([$submission]);
But the files cause
Filament\Forms\Components\BaseFileUpload::Filament\Forms\Components{closure}(): Argument #1 ($file) must be of type string, array given
because they haven't been cast properly as I understand it
Hm. No sure why the FileUpload stores as array but requires a string.
as an example is what is saved. But..
we should cast it and I think because we are not casting it, it's storing incorrectly. I am thinking I need to manually cast it on save 😦
Or I create a new view for file uploads which store in a file_uploads table with the needed casts.
Where's the filename though?
Oh didn't know we have a
->storeFileNamesIn
Yeah, it’s ok I think I’ve got it though
@toeknee_iom storeFileNamesIn() is not the same thing
it is used to store the file names in a column, not a storage location
You spotted my error as I did when Dennis mentioned it 😂
@danharrin so, I have the form which is a standard form builder form, with a statePath set on a wizard tab for documents. A document shows storage disk local and I've removed all config from the file upload field and this is what is stored in $this->data on saving. This is in a livewire component. Is there some docs that explains how best to handle the file saving on this form within the livewire component as I suspect we need to handle it custom?
IT doesn't seem to follow standard livewire file uploads, as document is array as the anove
Think I've got it, missed that files can be multiple so it's an array first then a sub array.
FYI resolved, ensure using $this->form->getState() when saving which will ensure the files are processed etc and then you can loop through. I was using $this->data as we push and map to it.