F
Filament3mo ago
Zod

Custom modal inside repeater

Is it possible to open a modal when adding a new row to a repeater with input fields and populate the repeater row fields with data from the modal?
12 Replies
Mansoor Khan
Mansoor Khan3mo ago
You can replace requiresConfirmation method with any methods you want. And maybe also try to pass a custom action.
Repeater::make('members')
->schema([
// ...
])
->addAction(
fn (Action $action) => $action->requiresConfirmation(),
)
Repeater::make('members')
->schema([
// ...
])
->addAction(
fn (Action $action) => $action->requiresConfirmation(),
)
Zod
Zod3mo ago
Thanks, but how would I render inputs that return values to the repeater? Or submit to the repeater It should create a new row with the values filled in the modal
Mansoor Khan
Mansoor Khan3mo ago
I am on the phone, i assume the following should work. The action you pass can open up a modal and can have a form. https://filamentphp.com/docs/3.x/actions/modals#modal-forms And the ->action() method of your custom action can update the Repeater field.
->action(function(Repeater $repeater){
$repeater->state() // pass the data to repeater field.
})
->action(function(Repeater $repeater){
$repeater->state() // pass the data to repeater field.
})
Try it and see if it works.. Its all about trial and error.
Zod
Zod3mo ago
Haha thanks mate! Will give it a try! I am getting the following error: Unresolvable dependency resolving [Parameter #0 [ <required> string $name ]] in class Filament\Forms\Components\Field ->addAction( fn (Action $action) => $action->action(function (array $data, Repeater $repeater) { dd($data); })->form([ TextInput::make('weight'), ]) )
Mansoor Khan
Mansoor Khan3mo ago
Possible share the stack trace.
Zod
Zod3mo ago
Flare
Unresolvable dependency resolving [Parameter #0 [ string $name ]] in class Filament\Forms\Components\Field - The error occurred at http://localhost/transport
toeknee
toeknee3mo ago
you haven't made it yet... wouldn't you need action->name('name iof action') ?
Mansoor Khan
Mansoor Khan3mo ago
Right... @Zod Share your code and lets what you have done. I think you are not setting up Field/Action correctly.
Zod
Zod3mo ago
Repeater::make(__('Goods')) ->relationship('transportGoods') ->schema([ Grid::make() ->columns(8) ->schema([ TextInput::make('description') ->required(), TextInput::make('width') ->required(), TextInput::make('depth') ->required(), TextInput::make('height') ->required(), Select::make('weight_type') ->options([ 'SINGLE' => 'Per type', 'TOTAL' => 'Total' ]) ->required(), TextInput::make('weight') ->required(), TextInput::make('amount') ->required(), ]) ])->addAction( fn (Action $action) => $action->action(function (array $data) { dd($data); })->form([ TextInput::make('description'), ]) ), The action works, I can get the data aswel. But when I add $repeater it gives the error on submit
toeknee
toeknee3mo ago
Waht error?
Zod
Zod3mo ago
Unresolvable dependency resolving [Parameter #0 [ <required> string $name ]] in class Filament\Forms\Components\Field I have built it with Get and Set now and it works ->action(function ($data, Set $set, Get $get) { $currentState = $get('goods') ?? []; $result = array_merge($currentState, [$data]); $set('goods', $result); });