Setting the default value of a TextInput within a Repeater

Hello, I'm trying to set the default value of TextInput within a Repeater using another field outside this repeater.
This is a simplified example of what I'm doing, unfortunately I'm not getting the value of cap field.
Any suggestions?

public static function form(Form $form): Form
{
return $form
->schema([
HiddenInput::make('cap'),
Repeater::make('numbers')
->schema([
TextInput::make('prefix')->default(fn (Get $get) => $get('../../cap')), // I will add a query that will use the value to retrieve data from DB
])
]);
}
Solution
Do you want to do this?

Forms\Components\Select::make('select')
    ->options([
        'option1' => 'Option 1',
        'option2' => 'Option 2',
        'option3' => 'Option 3',
    ])
    ->live()
    ->afterStateUpdated(function (Forms\Components\Select $component, ?string $state) {
        $repeater = $component->getContainer()->getComponent('data.repeater');

        $repeater->state(Arr::map($repeater->getState(), function (array $item) use ($state) {
            $item['prefix'] = $state;

            return $item;
        }));
    }),

Forms\Components\Repeater::make('repeater')
    ->schema([
        Forms\Components\TextInput::make('prefix')
            ->default(fn(Forms\Get $get): ?string => $get('../../select'))
    ]),
Was this page helpful?