Get Index of Repeater

Hello everyone, I’m working on a personal project: a Gym Management System. In this system, I need to create Workouts, and each workout is divided into multiple Divisions, with each division containing several Exercises. Here's the structure: Workout
Division 1
Exercise 1
Exercise 2
Exercise 3
Division 2
Exercise 1
Exercise 2
Exercise 3
Division 3
Exercise 1
Exercise 2
Exercise 3
To implement this, I’m using a Repeater field for the divisions. Each division contains fields for its name and related exercises. What I want is for the Division name to be generated automatically based on its position in the list (e.g., "Division 1", "Division 2", etc.) as new divisions are added. Currently, I’ve set a default value for the name field, but it’s always assigning the same name (e.g., "Division 1") to all divisions, instead of dynamically updating based on the index. Does anyone have suggestions or best practices for implementing this? Ideally, I’d like the names to update automatically based on their index in the Repeater. Thanks in advance for your help!
No description
1 Reply
Lucas de Mello
Lucas de MelloOP7d ago
Using the $get('../') method inside the repeater works.
Forms\Components\Section::make('Divisões do Treino')
->icon('phosphor-list-bullets-bold')
->description('Organize o treino em sessões distintas para facilitar o planejamento e execução.')
->schema([
Forms\Components\Repeater::make('Divisões')
->schema([
Forms\Components\TextInput::make('name')->required()
->default(fn ($get) => 'Treino ' . chr(64 + (count($get('../')) ?? 0))),
])
->addActionLabel('Adicionar Divisão')
])
Forms\Components\Section::make('Divisões do Treino')
->icon('phosphor-list-bullets-bold')
->description('Organize o treino em sessões distintas para facilitar o planejamento e execução.')
->schema([
Forms\Components\Repeater::make('Divisões')
->schema([
Forms\Components\TextInput::make('name')->required()
->default(fn ($get) => 'Treino ' . chr(64 + (count($get('../')) ?? 0))),
])
->addActionLabel('Adicionar Divisão')
])
Want results from more Discord servers?
Add your server