Item label for repeater

Hello guys. I am using a collapsed repeater with an item label. I need that label to be set to the room title. This is my code
Repeater::make('bedroom_option')
->itemLabel('Bedroom option')
->collapsed()
->inset()
->schema([
TextInput::make('room_title')
->reactive()
->label('Room title')
->required(),
Repeater::make('bedroom_option')
->itemLabel('Bedroom option')
->collapsed()
->inset()
->schema([
TextInput::make('room_title')
->reactive()
->label('Room title')
->required(),
Is there a way to set the item label to room title foreach item of the repeater ?
2 Replies
awcodes
awcodesβ€’2y ago
You can use closure customization in itemLabel. Ex:
->itemLabel(fn (array $state): ?string => Str::of($state['key'])->title()->replace('_', ' ') ?? null)
->schema([
Forms\Components\TextInput::make('key')->required()->columnSpan('full'),
Forms\Components\TextInput::make('url')->required()->columnSpan('full'),
Forms\Components\TextInput::make('alt'),
Forms\Components\TextInput::make('width'),
Forms\Components\TextInput::make('height'),
]),
->itemLabel(fn (array $state): ?string => Str::of($state['key'])->title()->replace('_', ' ') ?? null)
->schema([
Forms\Components\TextInput::make('key')->required()->columnSpan('full'),
Forms\Components\TextInput::make('url')->required()->columnSpan('full'),
Forms\Components\TextInput::make('alt'),
Forms\Components\TextInput::make('width'),
Forms\Components\TextInput::make('height'),
]),
DianaMujoiu
DianaMujoiuOPβ€’2y ago
It's working. Thank you πŸ™
Want results from more Discord servers?
Add your server