How to customize Repeater form events?

I've read the documentation found on https://filamentphp.com/docs/2.x/forms/advanced#using-form-events but I don't understand any single thing. I don't understand how to implement this:
protected function setUp(): void
{
parent::setUp();

$this->registerListeners([
'repeater::deleteItem' => [
function (Component $component, string $statePath, string $uuidToDelete): void {
if ($component->isDisabled()) {
return;
}

if ($statePath !== $component->getStatePath()) {
return;
}

// Delete item with UUID `$uuidToDelete`
},
],
]);
}
protected function setUp(): void
{
parent::setUp();

$this->registerListeners([
'repeater::deleteItem' => [
function (Component $component, string $statePath, string $uuidToDelete): void {
if ($component->isDisabled()) {
return;
}

if ($statePath !== $component->getStatePath()) {
return;
}

// Delete item with UUID `$uuidToDelete`
},
],
]);
}
Filament
Advanced - Form Builder - Filament
The elegant TALL stack form builder for Laravel artisans.
7 Replies
vahnmarty
vahnmartyOP2y ago
I tried using this:
return [
Repeater::make('parents')
->schema([
])
->registerListeners([
'repeater::deleteItem' =>[],
'repeater::createItem' =>[],
])
];
return [
Repeater::make('parents')
->schema([
])
->registerListeners([
'repeater::deleteItem' =>[],
'repeater::createItem' =>[],
])
];
What I want is to create a model after the user clicks the createItem. So adding Parent::create([])
Dennis Koch
Dennis Koch2y ago
The docs talk about the (Livewire) „component“ which is the Page in your case, not the Field. You can use the methods inside the setup method.
vahnmarty
vahnmartyOP2y ago
So, I have a livewire component ApplicationForm.php and I added this:
protected function setUp(): void
{
parent::setUp();

$this->registerListeners([
'repeater::deleteItem' => [
function (Component $component, string $statePath, string $uuidToDelete): void {

dd($uuidToDelete);

if ($component->isDisabled()) {
return;
}

if ($statePath !== $component->getStatePath()) {
return;
}



// Delete item with UUID `$uuidToDelete`
},
],
]);
}
protected function setUp(): void
{
parent::setUp();

$this->registerListeners([
'repeater::deleteItem' => [
function (Component $component, string $statePath, string $uuidToDelete): void {

dd($uuidToDelete);

if ($component->isDisabled()) {
return;
}

if ($statePath !== $component->getStatePath()) {
return;
}



// Delete item with UUID `$uuidToDelete`
},
],
]);
}
Then I tested it by clicking a delete in the repeater, the dd() did not fire. The ->setUp() kinda belongs to a custom field.
awcodes
awcodes2y ago
Yes it does.
Dennis Koch
Dennis Koch2y ago
Oh, do you need to extend the Repeater then? 🤔
vahnmarty
vahnmartyOP2y ago
So the docs is referring to a custom field and not for my livewire page?
backtrackjack
backtrackjack17mo ago
I ran into the same problem. dd() does not fire when I create a protected function setUp() with $this->registerListeners while listening for any repeater::x event but it works when I add the registerListeners() method to the repeater field
Want results from more Discord servers?
Add your server