© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
2 replies
lucianosnchz

ItemLabel Repeater Index In Input

Hello! I'm encountering what seems to be a basic issue with the following: I'm working on a "static" repeater where repeaters already have a default number of items, and users only need to fill in the values. I've managed to set the Label for each item based on its index. However, now I want to automatically fill in the default value of the attribute_id field with the ID of each item in the repeater. Any suggestions on how I could achieve this? Thank you very much!

                Grid::make('default')->schema([
                    Repeater::make('attributesRepeater')
                        ->relationship('attributesRepeater')
                        ->label('Atributos')
                        ->itemLabel(function ($uuid, $component) {
                            $keys = array_keys($component->getState());
                            $index = array_search($uuid, $keys);


                            $attributes = $this->getOwnerRecord()->attributes;

                            return $attributes[$index]->name;

                        })
                        ->schema([

                            TextInput::make('attribute_id')
                                ->hidden()
                                ->default($attributes[$index]->id),

                            Forms\Components\TextInput::make('value')
                                ->required()
                                ->label('Valor')
                                ->live(onBlur: true)
                                ->maxLength(255),

                        ])
                        ->grid(2)
                        ->defaultItems($this->getOwnerRecord()->attributes->count()),

                ]),
                Grid::make('default')->schema([
                    Repeater::make('attributesRepeater')
                        ->relationship('attributesRepeater')
                        ->label('Atributos')
                        ->itemLabel(function ($uuid, $component) {
                            $keys = array_keys($component->getState());
                            $index = array_search($uuid, $keys);


                            $attributes = $this->getOwnerRecord()->attributes;

                            return $attributes[$index]->name;

                        })
                        ->schema([

                            TextInput::make('attribute_id')
                                ->hidden()
                                ->default($attributes[$index]->id),

                            Forms\Components\TextInput::make('value')
                                ->required()
                                ->label('Valor')
                                ->live(onBlur: true)
                                ->maxLength(255),

                        ])
                        ->grid(2)
                        ->defaultItems($this->getOwnerRecord()->attributes->count()),

                ]),
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Custom itemLabel in Repeater
FilamentFFilament / ❓┊help
3y ago
Incremental itemLabel for repeater
FilamentFFilament / ❓┊help
2y ago
itemLabel in repeater for first schema
FilamentFFilament / ❓┊help
3y ago
[Test] itemLabel function from Repeater
FilamentFFilament / ❓┊help
12mo ago