Incremental itemLabel for repeater
Hello everyone. đ
I know this question has already been asked several times, but I haven't found any answers...
Basically my question is simple: I'm creating a form with a repeater (questions). In this repeater, I've a second one (answers).
And I want to put an itemLabel in this second repeater with an incremental number (Answer 1, Answer 2, Answer 3, etc.).
Thanks for you help đ
Solution:Jump to solution
I found a solution on Github for those who are looking too :
```php
->itemLabel(function ($state, $component) {
$key = array_search($state, $component->getState());...
GitHub
How to add index on Repeater itemLabel ? · filamentphp filament · D...
https://filamentphp.com/docs/3.x/forms/fields/repeater#adding-a-label-to-repeater-items-based-on-their-content ->itemLabel(fn (array $state): ?string => $state['name'] ?? null)
3 Replies
Solution
I found a solution on Github for those who are looking too :
And that work like expected đ„ł
Source : https://github.com/filamentphp/filament/discussions/8565#discussioncomment-7031649
GitHub
How to add index on Repeater itemLabel ? · filamentphp filament · D...
https://filamentphp.com/docs/3.x/forms/fields/repeater#adding-a-label-to-repeater-items-based-on-their-content ->itemLabel(fn (array $state): ?string => $state['name'] ?? null)
hi
@Alexandre hi sorry for mentioned you here. may i know that this code still function ? because i try implement to my project but seems not working
Hello,
Yes, it still works. I've set it up in a quiz management system where I have groups of questions, with questions and answers. The questions are in a repeater and so are the answers.
For the first group, I had to do it like this to manage the number (see screenshot one) :
I handled the reply counter in the same way as my post above (see screenshot 2):
Are you receiving an error?