Validate not triggering

Hi , I’m facing an issue where submitting the “Create ITRF” modal results in an internal server error whenever a required field (like item_name) is left empty. Here's a simplified version of my setup: * In the modal footer actions, I'm using:
$this->extraModalFooterActions(fn (Action $action) => [
Action::make('create')
->label('Create ITRF')
->requiresConfirmation()
->color('success')
->action(function (Component $livewire) {
$this->handleItrfStageOneAction($livewire->mountedActionsData[0], ['isDraft' => false]);
})
->cancelParentActions(),
]);
$this->extraModalFooterActions(fn (Action $action) => [
Action::make('create')
->label('Create ITRF')
->requiresConfirmation()
->color('success')
->action(function (Component $livewire) {
$this->handleItrfStageOneAction($livewire->mountedActionsData[0], ['isDraft' => false]);
})
->cancelParentActions(),
]);
* And inside the handler:
protected function handleItrfStageOneAction(array $data, array $arguments): void
{
$result = $this->process(function (?Model $record = null) use ($data, $arguments) {
// ... handles request, ITRF, and carts logic
foreach ($data['carts'] as $cartData) {
Cart::create([
'item_name' => $cartData['item_name'],
// ...
]);
}
});

if (! $result) {
$this->failure();
return;
}

$this->success();
}
protected function handleItrfStageOneAction(array $data, array $arguments): void
{
$result = $this->process(function (?Model $record = null) use ($data, $arguments) {
// ... handles request, ITRF, and carts logic
foreach ($data['carts'] as $cartData) {
Cart::create([
'item_name' => $cartData['item_name'],
// ...
]);
}
});

if (! $result) {
$this->failure();
return;
}

$this->success();
}
The problem seems to be that form validation isn’t triggering the handleItrfStageOneAction() is executed, so the request goes straight to the database and fails on NOT NULL constraints. I’d appreciate any guidance on: * Why the validation might be skipped in this context. * Whether there’s a better way to trigger validation before the action logic runs. * How to make Filament show inline field errors rather than crashing with SQL exceptions. Thanks in advance for your help!
Solution:
workaround ```php Action::make('save_draft') ->label('Save as Draft')...
Jump to solution
1 Reply
Solution
Rolland
Rolland3mo ago
workaround
Action::make('save_draft')
->label('Save as Draft')
->color('gray')
->action(function (Component $livewire) {
$this->validateItrfStageOneFormData($livewire);
$this->handleItrfStageOneAction($livewire->mountedActionsData[0], ['isDraft' => true]);
})
->after(fn (Action $action) => $action->cancelParentActions());
Action::make('save_draft')
->label('Save as Draft')
->color('gray')
->action(function (Component $livewire) {
$this->validateItrfStageOneFormData($livewire);
$this->handleItrfStageOneAction($livewire->mountedActionsData[0], ['isDraft' => true]);
})
->after(fn (Action $action) => $action->cancelParentActions());
protected function validateItrfStageOneFormData(Component $livewire, ?string $formDataKey = null): void
{
$livewire->validate(
rules: 'some-rules',
attributes: 'some-attributes',
);
}
protected function validateItrfStageOneFormData(Component $livewire, ?string $formDataKey = null): void
{
$livewire->validate(
rules: 'some-rules',
attributes: 'some-attributes',
);
}
i am using ->after(fn (Action $action) => $action->cancelParentActions()) so that the modal not getting closed when the user submit empty fields or if there's any fields errors.

Did you find this page helpful?