File Uploads - clear the input field

What seems to be the problem: File Input not cleared. I want it to go back to saying No file chosen after upload.

Steps to Reproduce: Create file input field. Upload a file. Save the file and set the public property that is wire:model with the input field to null. Confusingly, client still shows the previously selected filename.

Are you using the latest version of Livewire: 1.2

Do you have any screenshots or code examples:

Form;

<input wire:model="newimage" name="newimage" type="file" class="form-control">

Component;

        if($this->newimage) {
            $slide->image = $this->newimage->store('/','slides');
        }
        $slide->save();
        $this->newimage = null;

By changing the design I was able to implement a workaround by removing the file input from the dom between uploads.

I found this which described the file input field as being immutable;

I’ve considered, but not tried, changing the dom for the element in some way, eg with some other livewire attribute echoed to the input field so that livewire sees the element as needing re-rendering.

You could try to just append a random id to the field. That should force it to swap out. id="{{ rand() }}".

1 Like