#Repeater get data from form

3 messages · Page 1 of 1 (latest)

olive schooner
#

I'm new to filament and I want to be able to access the data from the form in the repeater. I have a select in my schema and a repeater. I want to use the data in my select and use it in a query for my repeater. I feel like the answer is very simple but I have been stuck for a while

This is my form:
public static function form(Form $form): Form
{
return $form
->schema([
Select::make('layout_mode')
->options([
'portrait' => 'Portrait',
'landscape' => 'Landscape',
])
->required()
->reactive()
->default('portrait'),

            Repeater::make('schedule_data.schedule')
                ->label('Content Data')
                ->schema([
                    Select::make('content_id')
                        ->label('Content')
                        ->required()
                        ->options(function (callable $get) {
                            return self::getContentOptions($get);
                        }),

                    TextInput::make('time')
                        ->label('Display time in seconds')
                        ->numeric(),
                ])
                ->columns(2)
                ->columnSpanFull(),
        ]);

}

This is the function I use to get the options in my repeater:

protected static function getContentOptions(callable $get): array
{
$layoutMode = $get('layout_mode');
$tenantId = Filament::getTenant()?->id;

    if ($tenantId && $layoutMode) {
        return Content::where('organization_id', $tenantId)
            ->where('layout_mode', $layoutMode)
            ->pluck('name', 'id')
            ->toArray();
    }

    return [];
}

How can I pass along the selected value in my select to my repeater?

magic lanceBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

spiral tulip
#

Its been a few days, hope you see this (or have already solved it). But you can use this in your repeater. Using a closure will make the method re-evaluate when using the repeater.

function(GET $get) {
  $get('layout_mode')
}

If you want to set multiple rows in the repeater you can use SET $set instead of get, repeater structure is

 
 $structure = [
['field' => 'value'],
['field2' => 'value2']
]