Skip to content

requiredIf not working with FileUpload component #15954

Open
@mariavilaro

Description

@mariavilaro

Package

filament/filament

Package Version

v3.3.3

Laravel Version

v12.1.1

Livewire Version

v3.6.1

PHP Version

PHP 8.4.5

Problem description

In a form with a select with two options and two dependent fields: a fileupload and a richeditor. Using requiredIf(), when the selected option is "1" the fileupload field is required, and when the selected option is "2" the richeditor is required.

The problem is that the fileupload is not required correctly, and you can create a record with type "1" without uploading anything. When selecting type "2" the richeditor is required so you can't create a record with type "2" and no text.

The fileupload is always required if you use ->required(), so I think this is a problem just with the conjuntion fileupload + requiredIf().

Expected behavior

You shouldn't be able to submit the form if you choose "1" in the select and don't upload the file, and the error message "The file field is required when type is 1" should appear.

Steps to reproduce

use Filament\Forms;

Forms\Components\Select::make('type')
    ->required()
    ->options([
        1 => trans('File'),
        2 => trans('Text'),
    ]),
Forms\Components\FileUpload::make('filename')
    ->requiredIf('type', 1),
Forms\Components\RichEditor::make('text')
    ->requiredIf('type', 2)
]);

Reproduction repository (issue will be closed if this is not valid)

https://github.com/mariavilaro/filament-issue-requiredif-fileupload

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    Todo

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions