I have a correctly working FilamentPHP v2 repeater. I am trying to add a 'confirm delete' modal that the user must accept before the delete action proceeds, a pretty normal use case.
There doesn't seem to be anything built in to handle this, and the views are generated - so firing my own events from the delete click in the component seems like it will be tricky.
I have also tried using the built-in events, such as repeater:deleteItem - but this fires AFTER the delete has taken place, which is too late as it has already been removed from the interface.
Is there a standard way to deal with this that I've missed?
You can add the confimation dialog as document said.
Here's an example:
Updated (V2): Since the previous solution doesn't work in version 2, Below two options are available:
First Option: You can override the repeater component to add a confirmation. To do this, you need to publish filament form views using
php artisan vendor:publish --provider="Filament\Forms\FormsServiceProvider"and then customize the repeater component located inresources/views/vendors/forms/components/repeater.blade.phpand add onclick event to the trash icon.Here's an example of final code:
You can search for
Here we add our onclick eventto easily find customization.Second Option: It seems you tried
repeater::deleteItem, but there's a point. When you define a listener with the same name, it will not override for some reason, and because of that, you still have the default behavior.To override that listener, it tried something like this:
First, create a new repeater component class.
For example, let's create
Repeater.phpinapp/Filament/Forms/Compontent. This class extends Filament's Repeater component class.Then, you need to bind Filament's Repeater to your new Repeater.
In
AppServiceProvider:Now
repeater::deleteItemdoes whatever you say.