F
Filament2mo ago
wazkaz

Repeater open conditionally.

Is it possible to open a repeater conditionally? For example, when a modal form opens and it contains several repeater items that are collapsed by default — is there a way to have one repeater item open while the others remain collapsed? If yes, how?
Solution:
Found a solution ``` ->collapsed(function (Livewire $livewire, ?ComponentContainer $item): bool { // When creating, keep items expanded if ($livewire->mountedActionName === 'create') {...
Jump to solution
1 Reply
Solution
wazkaz
wazkaz2mo ago
Found a solution
->collapsed(function (Livewire $livewire, ?ComponentContainer $item): bool {
// When creating, keep items expanded
if ($livewire->mountedActionName === 'create') {
return false;
}

// For edit mode, check if this specific item is the clicked option
if ($item) {
// Get the raw state from the ComponentContainer
$state = $item->getRawState();
$isClickedOption = $state['is_clicked_option'] ?? false;

// Expand the clicked option (return false), collapse others (return true)
return !$isClickedOption;
}

// Default: collapse items in edit mode
return true;
})
->collapsed(function (Livewire $livewire, ?ComponentContainer $item): bool {
// When creating, keep items expanded
if ($livewire->mountedActionName === 'create') {
return false;
}

// For edit mode, check if this specific item is the clicked option
if ($item) {
// Get the raw state from the ComponentContainer
$state = $item->getRawState();
$isClickedOption = $state['is_clicked_option'] ?? false;

// Expand the clicked option (return false), collapse others (return true)
return !$isClickedOption;
}

// Default: collapse items in edit mode
return true;
})

Did you find this page helpful?