F
Filament16mo ago
mtbossa

How to trigger a validation error from configureCreateAction() relation manager

I need to make 2 fields have an error (red border and text below) after some code inside configureCreateAction() in a relation manager. Is it possible?
2 Replies
LeandroFerreira
LeandroFerreira16mo ago
what code did you try?
mtbossa
mtbossaOP16mo ago
public function configureCreateAction(Tables\Actions\CreateAction $action) : void{
$action
->using(function (array $data, string $model, RelationManager $livewire) use ($action): Model|null {
$create_field_time_slot = App::make(CreateFieldTimeSlotAction::class);
try {
return $create_field_time_slot->handle(
field_id: $livewire->ownerRecord->id,
isoweekday: IsoWeekday::from($data['isoweekday']),
start_time: $data['start_time'],
end_time: $data['end_time'],
price: $data['price'],
reservation_discount: $data['reservation_discount'] ?? null,
);
} catch (TimeSlotOverlaps $exception) {
Notification::make()
->title(__('validation.overlaps'))
->body(__('validation.overlaps_start_end_time'))
->danger()
->send();

$action->halt();
}
});

parent::configureCreateAction($action);
}
public function configureCreateAction(Tables\Actions\CreateAction $action) : void{
$action
->using(function (array $data, string $model, RelationManager $livewire) use ($action): Model|null {
$create_field_time_slot = App::make(CreateFieldTimeSlotAction::class);
try {
return $create_field_time_slot->handle(
field_id: $livewire->ownerRecord->id,
isoweekday: IsoWeekday::from($data['isoweekday']),
start_time: $data['start_time'],
end_time: $data['end_time'],
price: $data['price'],
reservation_discount: $data['reservation_discount'] ?? null,
);
} catch (TimeSlotOverlaps $exception) {
Notification::make()
->title(__('validation.overlaps'))
->body(__('validation.overlaps_start_end_time'))
->danger()
->send();

$action->halt();
}
});

parent::configureCreateAction($action);
}
Instead of making a Notification, I'd like to set some error message in the start_time and end_time fields
Want results from more Discord servers?
Add your server