2

I am trying to access field_1 value inside the repeater

return $form->schema([
    Select::make('field_1')->reactive()->options(['a','b','c']),
    Repeater::make('repeater_1')->schema([
        TextInput::make('field_2')->default(fn (Closure $get) => $get('field_1')),
    ]),
]);
LIGHT
  • 5,604
  • 10
  • 35
  • 78

1 Answers1

4
TextInput::make('field_2')->default(fn (Closure $get) => $get('../../field_1')),

https://filamentphp.com/docs/2.x/forms/fields#using-get-to-access-parent-field-values

Dan Harrin
  • 889
  • 6
  • 17
  • Thanks Dan. I actually found few hours after I posted the question. I forgot to answer it here. Thank you tho :) – LIGHT Sep 22 '22 at 13:25
  • It works thanks. But why do we need '../../' instead of '../' ? – Rafat Rashid Rahi Aug 25 '23 at 05:31
  • @RafatRashidRahi Because `../` allows you to access other items in the same repeater and `../../` goes a step further to allow you to access fields outside of the repeater. This is explained in the docs if you read them. – Dan Harrin Aug 25 '23 at 08:40