© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
2 replies
Jon Mason

FileUpload in form resets form fields on upload

I have a form that contains a
FileUpload
FileUpload
field. It works fine, except when a user fills out the form, and then subsequently uploads a file, it resets the fields on the form to their defaults. So you have to remember to upload the file first, then set your form fields, then click save.

 Radio::make('my_radio_field_that_gets_reset')
                ->required()
                ->default(1)
                ->boolean(),
            FileUpload::make('document')
                ->label('Upload Document')
                ->preserveFilenames()
                ->acceptedFileTypes(['application/pdf'])
                ->storeFiles(false)
 Radio::make('my_radio_field_that_gets_reset')
                ->required()
                ->default(1)
                ->boolean(),
            FileUpload::make('document')
                ->label('Upload Document')
                ->preserveFilenames()
                ->acceptedFileTypes(['application/pdf'])
                ->storeFiles(false)


The file upload seems to be treated as its own form within a form or something, and I don't know how to tell it to just maybe do it all at once....is there a good work-around?

Here's my save method:

public function save(): void
    {
        $data = $this->form->getState();

        if (isset($data['document']) && $data['document'] instanceof TemporaryUploadedFile)         {
            try {

               //save the file.
            } catch (\InvalidArgumentException $e) {

              //...
            }
        }

}
public function save(): void
    {
        $data = $this->form->getState();

        if (isset($data['document']) && $data['document'] instanceof TemporaryUploadedFile)         {
            try {

               //save the file.
            } catch (\InvalidArgumentException $e) {

              //...
            }
        }

}
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

init upload programmatically on FileUpload component
FilamentFFilament / ❓┊help
16mo ago
Dynamic form fields based on dependant fields
FilamentFFilament / ❓┊help
3y ago
FileUpload failed to upload.
FilamentFFilament / ❓┊help
2y ago
Fileupload wouldn't upload.
FilamentFFilament / ❓┊help
3y ago