F
Filament12mo ago
AxlF

Add Items to Repeater with a Modal

Hey, I'm pretty sure it could work, but I don't get how. Basically I would like to add Items to a Repeater with a form in a Modal instead of an inline form. The modal should ask for postcode and city. The Repeater should show a compound string ("$postcode $city"). I get a modal as input form, but the values are not shown in the repeater
Repeater::make('location')
->schema([
TextInput::make('location'),
])
->addAction(function (Action $action) {
return $action->form([
TextInput::make('postcode')
->required(),
TextInput::make('city')
->required(),
]);
}),
Repeater::make('location')
->schema([
TextInput::make('location'),
])
->addAction(function (Action $action) {
return $action->form([
TextInput::make('postcode')
->required(),
TextInput::make('city')
->required(),
]);
}),
`
Solution:
``` Repeater::make('locations') ->schema([ Placeholder::make('location') ->label('')...
Jump to solution
2 Replies
AxlF
AxlFOP12mo ago
I think I got a working solution. Perhaps there is a better apporach, but for now it works.
Solution
AxlF
AxlF12mo ago
Repeater::make('locations')
->schema([
Placeholder::make('location')
->label('')
->content(fn (Get $get) => $get('postcode').' '.$get('city')),
])
->addAction(function ($action) {
return $action->form([
TextInput::make('postcode'),
TextInput::make('city'),
])
->action(function ($data, Set $set, Get $get) {
$currentState = $get('locations') ?? [];
$result = array_merge($currentState, [$data]);
$set('locations', $result);
});
})
Repeater::make('locations')
->schema([
Placeholder::make('location')
->label('')
->content(fn (Get $get) => $get('postcode').' '.$get('city')),
])
->addAction(function ($action) {
return $action->form([
TextInput::make('postcode'),
TextInput::make('city'),
])
->action(function ($data, Set $set, Get $get) {
$currentState = $get('locations') ?? [];
$result = array_merge($currentState, [$data]);
$set('locations', $result);
});
})
Want results from more Discord servers?
Add your server