protonemedia / laravel-splade

💫 The magic of Inertia.js with the simplicity of Blade 💫 - Splade provides a super easy way to build Single Page Applications (SPA) using standard Laravel Blade templates, and sparkle it to make it interactive. All without ever leaving Blade.
https://splade.dev
MIT License
1.47k stars 111 forks source link

Validation error after deleting uploaded file using Filepond #638

Open thannaske opened 5 months ago

thannaske commented 5 months ago

Description

When using the Filepond component for uploading multiple files there's an issue when the user removes a file that has already been uploaded. The validation of the subsequent request then fails with the following error:

The attachments.0 field must be a file.

This validation error is raised, although there should no attachment.0 field anymore at all. It seems like deleting a file from the Filepond UI doesn't result in the field being removed from the form payload.

The request validation on the backend looks like this (and works fine when uploading a file and then immediately submitting the form):

<?php

// [...]
use Illuminate\Foundation\Http\FormRequest;
use ProtoneMedia\Splade\FileUploads\HasSpladeFileUploads;

class MessageRequest extends FormRequest implements HasSpladeFileUploads
{
    // [...]   

    public function rules(): array
    {
        return [
            'attachments.*' => ['sometimes', 'file', 'max:102400'],
            // [...]
        ];
    }
}

Steps To Reproduce Issue

  1. Create a simple form with the Filepond upload component
  2. Point the form towards a controller that performs a input validation
  3. Upload a file
  4. Remove the file using the Filepond UI
  5. Submit the form
  6. Observe the validation error