How to validate a single field?

Is there a ->validateOnly in filament? I want to call it using ->afterStateUpdated()
2 Replies
LeandroFerreira
LeandroFerreira13mo ago
$livewire->validateOnly()
vahnmarty
vahnmarty13mo ago
TextInput::make('student.baptism_year')
->label('Baptism Year')
->numeric()
->integer()
->minLength(4)
->maxLength(4)
->lazy()
->afterStateUpdated(function(Livewire $livewire, Closure $get, $state){
$livewire->validateOnly('student.baptism_year');

if( strlen($state) == 4){
$this->autoSaveStudent('baptism_year', $state);
}
}),
TextInput::make('student.baptism_year')
->label('Baptism Year')
->numeric()
->integer()
->minLength(4)
->maxLength(4)
->lazy()
->afterStateUpdated(function(Livewire $livewire, Closure $get, $state){
$livewire->validateOnly('student.baptism_year');

if( strlen($state) == 4){
$this->autoSaveStudent('baptism_year', $state);
}
}),
Like this? Cool, I got it. 1. I fixed the instance
use Livewire/Component as Livewire;
use Livewire/Component as Livewire;
2. Apply it in the lifecycle
$livewire->validateOnly('data.student.baptism_year');
$livewire->validateOnly('data.student.baptism_year');
How about for array properties like Repeater? wow, I could just do this:
->afterStateUpdated(function(Livewire $livewire, Closure $get, Component $component, $state){
$livewire->validateOnly($component->getStatePath());

$this->autoSaveSibling($get('id'), 'personal_email', $state);
}),
->afterStateUpdated(function(Livewire $livewire, Closure $get, Component $component, $state){
$livewire->validateOnly($component->getStatePath());

$this->autoSaveSibling($get('id'), 'personal_email', $state);
}),