F
Filament2w ago
CROK

FileUpload form field and it's default values

Hello everyone. I have a problem with FileUpload form field on my custom page. I get a record from secondary db with file position and i want to show it as a default value for current form field. On this moment I made a default filament 4 resource with linked field from db to the FileUpload form field. In result i have seen that db contains name of file and edit page shows that file as already uploaded. In thay case if i set default value as array of strings with filenames/position of the file in storage/app/private. But then i tried to made same form with same default value on my custom page then the file not appears. Here is how i tried to made it: app/Filament/Pages/TestForm
<?php

namespace App\Filament\Pages;

use Filament\Forms\Components\FileUpload;
use Filament\Pages\Page;
use Filament\Schemas\Schema;
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;

class TestForm extends Page
{

public function form(Schema $schema): Schema
{
return $schema
->components([
FileUpload::make('upd')
->default(['udp/thesis.txt']),
// ->default([TemporaryUploadedFile::createFromLivewire('udp/thesis.txt')]),
]);
}

protected string $view = 'filament.pages.test-form';
}
<?php

namespace App\Filament\Pages;

use Filament\Forms\Components\FileUpload;
use Filament\Pages\Page;
use Filament\Schemas\Schema;
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;

class TestForm extends Page
{

public function form(Schema $schema): Schema
{
return $schema
->components([
FileUpload::make('upd')
->default(['udp/thesis.txt']),
// ->default([TemporaryUploadedFile::createFromLivewire('udp/thesis.txt')]),
]);
}

protected string $view = 'filament.pages.test-form';
}
views/filament/pages/test-form.blade.php
<x-filament-panels::page>
<form>
{{$this->form}}
</form>
{{-- Page content --}}
</x-filament-panels::page>
<x-filament-panels::page>
<form>
{{$this->form}}
</form>
{{-- Page content --}}
</x-filament-panels::page>
I know that array of form data contains array TemporaryUploadFile objects and i have tried to made it to show it on the FileUpload field but have a same problem with not appeared file in FileUpload Is any solution for similar cases with default value of FileUpload form field? Or someone know where is happening transformation of the value from db(title of the file) to the TemporaryUploadFile that i can take as an example
1 Reply
CROK
CROKOP2w ago
I have forgotten to add. Here is the position of the file
No description

Did you find this page helpful?