F
Filament2mo ago
o.m

How to handle custom Repeaters relationship?

I have a custom repeater and I am not sure how to handle the relationship. In the orginal one you could just pass the relationship but I'm not sure how to implement it for custom repeater.
<x-dynamic-component :component="$getFieldWrapperView()" :field="$field">
<div x-data x-sortable {{ $attributes->merge($getExtraAttributes())->class(['fi-repeater space-y-2']) }}>
<ul>
@foreach ($getChildComponentContainers() as $uuid => $item)
<li wire:key="{{ $this->getId() }}.{{ $item->getStatePath() }}.{{ $field::class }}"
x-sortable-item="{{ $uuid }}"
class="flex items-center gap-3 border p-2 rounded shadow-sm"
>
{{-- Radio Button --}}
<div class="shrink-0">
<input type="radio" name="default_option" value="{{ $uuid }}"
{{ $attributes->merge(['wire:click' => "markDefaultOption('$uuid')"]) }}
/>
</div>

{{-- Input Field --}}
<div class="flex-1">
{{ $item }}
</div>

{{-- Drag Handle --}}
<div x-sortable-handle class="cursor-move text-gray-500">
<x-heroicon-o-arrows-up-down class="w-5 h-5"/>
</div>

{{-- Delete Button --}}
<button type="button" wire:click="removeOption('{{ $uuid }}')"
class="text-red-500 hover:text-red-700">
<x-heroicon-o-trash class="w-5 h-5"/>
</button>
</li>
@endforeach
</ul>

</div>
</x-dynamic-component>
<x-dynamic-component :component="$getFieldWrapperView()" :field="$field">
<div x-data x-sortable {{ $attributes->merge($getExtraAttributes())->class(['fi-repeater space-y-2']) }}>
<ul>
@foreach ($getChildComponentContainers() as $uuid => $item)
<li wire:key="{{ $this->getId() }}.{{ $item->getStatePath() }}.{{ $field::class }}"
x-sortable-item="{{ $uuid }}"
class="flex items-center gap-3 border p-2 rounded shadow-sm"
>
{{-- Radio Button --}}
<div class="shrink-0">
<input type="radio" name="default_option" value="{{ $uuid }}"
{{ $attributes->merge(['wire:click' => "markDefaultOption('$uuid')"]) }}
/>
</div>

{{-- Input Field --}}
<div class="flex-1">
{{ $item }}
</div>

{{-- Drag Handle --}}
<div x-sortable-handle class="cursor-move text-gray-500">
<x-heroicon-o-arrows-up-down class="w-5 h-5"/>
</div>

{{-- Delete Button --}}
<button type="button" wire:click="removeOption('{{ $uuid }}')"
class="text-red-500 hover:text-red-700">
<x-heroicon-o-trash class="w-5 h-5"/>
</button>
</li>
@endforeach
</ul>

</div>
</x-dynamic-component>
5 Replies
o.m
o.mOP2mo ago
How I call it.
CustomRepeater::make('options')
->label('Manage Options')
->schema([
TextInput::make('label')->disableLabel(true)->required(),
])
->default(fn() => $this->options)
CustomRepeater::make('options')
->label('Manage Options')
->schema([
TextInput::make('label')->disableLabel(true)->required(),
])
->default(fn() => $this->options)
LeandroFerreira
LeandroFerreira2mo ago
->default(fn($livewire) => $livewire->options) public $options in your Create/Edit/View page
o.m
o.mOP2mo ago
Would like to clarify this one, you are referring to the custom page?
LeandroFerreira
LeandroFerreira2mo ago
where is $options ?
o.m
o.mOP2mo ago
Is it this? CustomRepeater::make('options') $options is already at EditGroupSetting.php this is the livewire component right?

Did you find this page helpful?