Setting an error message to a field manually

Is it possible to set an error message to a field manually within afterValidation? Using a notification doesn't really fit here.
->steps([
Step::make('group selection')
->schema([
Select::make('group_id')
->required()
->options(fn (): array => Group::query()
->pluck('name', 'id')
->toArray()),
])
->afterValidation(function (Get $get, Set $set): void {
calculations
if (some logic) {
set error message to group_id field
throw new Halt();
}
$set('next step', some stuff);
})
->steps([
Step::make('group selection')
->schema([
Select::make('group_id')
->required()
->options(fn (): array => Group::query()
->pluck('name', 'id')
->toArray()),
])
->afterValidation(function (Get $get, Set $set): void {
calculations
if (some logic) {
set error message to group_id field
throw new Halt();
}
$set('next step', some stuff);
})
Solution:
depending on what kinda place it is the field name may change
$livewire->addError('mountedActions.0.data.group_id', 'My error!');
$livewire->addError('mountedActions.0.data.group_id', 'My error!');
...
Jump to solution
1 Reply
Solution
frame
frame2w ago
depending on what kinda place it is the field name may change
$livewire->addError('mountedActions.0.data.group_id', 'My error!');
$livewire->addError('mountedActions.0.data.group_id', 'My error!');

Did you find this page helpful?