cpereiraweb
cpereiraweb
Explore posts from servers
TLCTuto's Laravel Corner
Created by cpereiraweb on 8/29/2023 in #💡filament
Validation doesn't work on form created with createOptionForm
Folks, I used the createOptionForm function to enable a new record creation form in a select field. Unfortunately, on this form, the unique() validation is not working. I followed a tip from Povilas in the code below, also without success:
// Document comes from a Leandro Ferreira package for document fields in pt_BR
Document::make('cpf')
->label('CPF')
->live()
->cpf('999.999.999-99')
->dehydrateStateUsing(fn(string $state): string => preg_replace('/[.-]+/', '', $state))
->unique()
->required()
->live()
->afterStateUpdated(function (Forms\Contracts\HasForms $livewire, Document $component) {
$livewire->validateOnly($component->getStatePath());
}),
// Document comes from a Leandro Ferreira package for document fields in pt_BR
Document::make('cpf')
->label('CPF')
->live()
->cpf('999.999.999-99')
->dehydrateStateUsing(fn(string $state): string => preg_replace('/[.-]+/', '', $state))
->unique()
->required()
->live()
->afterStateUpdated(function (Forms\Contracts\HasForms $livewire, Document $component) {
$livewire->validateOnly($component->getStatePath());
}),
It only validates required and not unique. When submitting the form, the key violation error occurs, as I tested an already registered document number. Can anyone tell me where I'm going wrong?
7 replies