FileUpload in form resets form fields on upload

I have a form that contains a 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) {

//...
}
}

}
1 Reply
LeandroFerreira
LeandroFerreira5mo ago
this shouldn't reset the fields. Did you add $this->form->fill() in the mount method? Are you using a statePath? Console errors? Try to share the whole code
Want results from more Discord servers?
Add your server