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
You can replace requiresConfirmation method with any methods you want.
And maybe also try to pass a custom action.
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
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.
Try it and see if it works..
Its all about trial and error.
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'),
])
)
Possible share the stack trace.
Flare
Unresolvable dependency resolving [Parameter #0 [ string $name ]] in class Filament\Forms\Components\Field - The error occurred at http://localhost/transport
you haven't made it yet... wouldn't you need action->name('name iof action') ?
Right...
@Zod Share your code and lets what you have done. I think you are not setting up Field/Action correctly.
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
Waht error?
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);
});