user1995781
user1995781

Reputation: 19463

Filament RepeatableEntry Remove Label

In Filament 3, how can I remove the label starting from row number 2? So that it does not repeating showing the same label.

enter image description here

RepeatableEntry::make('membership_records')
    ->schema([
        TextEntry::make('created_at')->label("Date"),
        TextEntry::make('description'),
    ])
    ->columns(2)
    ->inlineLabel(false)
    ->hiddenLabel()
    ->contained(false)

Upvotes: 0

Views: 832

Answers (1)

Majid M. Alzariey
Majid M. Alzariey

Reputation: 483

First modify your list to add a sort attribute which labels the first record.

You can control the visibility of the label based on the row number (sort attribute) by using hiddenLabel method. The hiddenLabel function receives a callback as an argument, where you can define the condition for which rows should hide label.

In your case, add some logic to hide the label for rows with a sort field value not equal to 0. Example code:

RepeatableEntry::make('classes')
    ->columnSpanFull()
    ->getStateUsing(function($record) {
        $items = $record->classes;
        foreach ($items as $key => $value) {
            $value->sort = $key;
        }
        return $items;
    })
    ->schema([
        TextEntry::make('created_at')
            ->label('Date')
            ->hiddenLabel(fn($record) => $record->sort != 0),
        TextEntry::make('name')
            ->label('Name')
            ->hiddenLabel(fn($record) => $record->sort != 0),
    ])
    ->columns(2)
    ->inlineLabel(false)
    ->hiddenLabel()
    ->contained(false)

Don't forget to replace 'classes' with 'membership_records', and also you need to make sure that you dont have a sort attribute in your record object.

Upvotes: 2

Related Questions