How to access $state inside a Repeater item ->collapsed()

Hello. So I can access $state to set the ->itemLabel() But I don't know how to access $state to set ->collapsed() to true of false depending on $state['done'] This is my code:
public static function form(Form $form): Form
{
return $form
->schema([

// [...]

Repeater::make('item')
->collapsible()
->relationship('items')
->schema([
TextInput::make('name')->required()->maxLength(255),
Toggle::make('done')->inline(false)->default(false),
RichEditor::make('description')->required(),
])
->itemLabel(fn (array $state): ?string => $state['name'] ?? null)
->collapsed(fn (array $state): bool => $state['done']), // THIS WON'T WORK. (I don't know how to access $state in collapsed)
]);

// [...]
}
public static function form(Form $form): Form
{
return $form
->schema([

// [...]

Repeater::make('item')
->collapsible()
->relationship('items')
->schema([
TextInput::make('name')->required()->maxLength(255),
Toggle::make('done')->inline(false)->default(false),
RichEditor::make('description')->required(),
])
->itemLabel(fn (array $state): ?string => $state['name'] ?? null)
->collapsed(fn (array $state): bool => $state['done']), // THIS WON'T WORK. (I don't know how to access $state in collapsed)
]);

// [...]
}
Thanks.
2 Replies
awcodes
awcodes2w ago
Collapsible applies to the repeater not to each individual item.
Hache_raw
Hache_raw2w ago
Yeah, that's what I saw by debugging. I just didn't find the words in english to explain my self. Is there a way to access to each item data? Or maybe just knowing the index since I can use something $get("items.$index.done") What I want to achieve is to make items that are "done" collapsed.
Want results from more Discord servers?
Add your server