F
Filament16mo ago
Daniel

Unique validation rule in repeater

Has anybody already handles unique validation rule in combination with Repeater fields?
2 Replies
Daniel
DanielOP16mo ago
Works, with some small adjustments:
->afterStateUpdated(function ($component, $state, $livewire) {
$items = $component->getContainer()->getParentComponent()->getOldState();
$livewire->resetErrorBag($component->getStatePath());
if (in_array($state, collect($items)->pluck($component->getName())->toArray())) {
$livewire->addError(
$component->getStatePath(),
__('validation.unique', ['attribute' => $component->getLabel()])
);
}
})
->afterStateUpdated(function ($component, $state, $livewire) {
$items = $component->getContainer()->getParentComponent()->getOldState();
$livewire->resetErrorBag($component->getStatePath());
if (in_array($state, collect($items)->pluck($component->getName())->toArray())) {
$livewire->addError(
$component->getStatePath(),
__('validation.unique', ['attribute' => $component->getLabel()])
);
}
})
Want results from more Discord servers?
Add your server