F
Filament6mo ago
riz

How to check if Fileupload is filled

How to check a fileupload component is filled, like in the code below I want to enable the toggle component only when textinput and fileupload is filled.. I tried $get('attachments') to no avail
Forms\Components\TextInput::make('first_name'),

Forms\Components\FileUpload::make('attachments')
->multiple(),

Forms\Components\Toggle::make('is_toggled')
->onIcon('heroicon-m-user')
->offIcon('heroicon-m-user')
->onColor('success')
->offColor('')
->dehydrated()
->disabled(fn (Get $get) => $get('first_name') === null)
Forms\Components\TextInput::make('first_name'),

Forms\Components\FileUpload::make('attachments')
->multiple(),

Forms\Components\Toggle::make('is_toggled')
->onIcon('heroicon-m-user')
->offIcon('heroicon-m-user')
->onColor('success')
->offColor('')
->dehydrated()
->disabled(fn (Get $get) => $get('first_name') === null)
1 Reply
DrByte
DrByte6mo ago
Sometimes I find it better to use $set from the conditional component, to tell the destination component what to do. A good example in the docs is setting a slug from a title textfield. https://filamentphp.com/docs/3.x/forms/advanced#generating-a-slug-from-a-title
I imagine if you combine it with a $get on the other field you can make the two work together to determine the status of the 3rd. ie: on both the text and file field put some logic that gets the value of the other, and if the values for those two "pass" then $set the toggle field.