steexd
steexd
FFilament
Created by steexd on 11/14/2024 in #❓┊help
Dynamic Repeater based on FileUpload->multiple() files
Hi everyone! I’m working on a feature in Filament where I’d like to create a repeater that contains basic metadata fields like title and description. The repeater should automatically generate entries based on the number of files uploaded in a FileUploader field (one entry per file). Here’s an example of the schema I’m currently working with:
public static function form(Form $form): Form
{
return $form
->schema([

Section::make(__('Media upload'))
->schema([
FileUpload::make('filepath')
->label(__('Media'))
->disk('public')
->directory('media')
->required()
->multiple()
]),

Section::make(__('Media details'))
->schema([
Repeater::make('media_metadata')
->schema([
Grid::make()
->schema([
TextInput::make('title')
->label(__('Title'))
->required(),

Textarea::make('description')
->label(__('Description'))
])
->columns(2)
])
->defaultItems(0)
->reorderable(false)
->deletable(false)
->addable(false)
]),
]);
}
public static function form(Form $form): Form
{
return $form
->schema([

Section::make(__('Media upload'))
->schema([
FileUpload::make('filepath')
->label(__('Media'))
->disk('public')
->directory('media')
->required()
->multiple()
]),

Section::make(__('Media details'))
->schema([
Repeater::make('media_metadata')
->schema([
Grid::make()
->schema([
TextInput::make('title')
->label(__('Title'))
->required(),

Textarea::make('description')
->label(__('Description'))
])
->columns(2)
])
->defaultItems(0)
->reorderable(false)
->deletable(false)
->addable(false)
]),
]);
}
Is there a simple or recommended way to achieve this? Ideally, the repeater field would also update dynamically if files are added or removed from the FileUpload field... Thanks in advance for your help!
5 replies
FFilament
Created by steexd on 6/5/2023 in #❓┊help
Customizing options labels in getRecordSelect() with additional information
->headerActions([
AttachAction::make()
->form(fn (AttachAction $action): array => [
$action
->recordSelect(function ($select) {
$select->options(function () use ($select) {
$options = $select->getOptions();
$formattedOptions = [];
foreach ($options as $value => $label) {
$model = Lotto::find($value);
$formattedLabel = 'Test label';
$formattedOptions[$value] = $formattedLabel;
}
return $formattedOptions;
});
return $select;
})
->preloadRecordSelect()
->getRecordSelect()
->label('Lotto botanica'),
Forms\Components\TextInput::make('grammi_utilizzati')
->required()
->numeric()
->minValue(1)
->mask(fn (TextInput\Mask $mask) => $mask
->numeric(),
)
->suffix('g'),
])
])
->headerActions([
AttachAction::make()
->form(fn (AttachAction $action): array => [
$action
->recordSelect(function ($select) {
$select->options(function () use ($select) {
$options = $select->getOptions();
$formattedOptions = [];
foreach ($options as $value => $label) {
$model = Lotto::find($value);
$formattedLabel = 'Test label';
$formattedOptions[$value] = $formattedLabel;
}
return $formattedOptions;
});
return $select;
})
->preloadRecordSelect()
->getRecordSelect()
->label('Lotto botanica'),
Forms\Components\TextInput::make('grammi_utilizzati')
->required()
->numeric()
->minValue(1)
->mask(fn (TextInput\Mask $mask) => $mask
->numeric(),
)
->suffix('g'),
])
])
I was trying to customize the labels of the options with this code, but I'm having trouble. What am I doing wrong? Thank you.
6 replies