Validate Before Action Modal Renders
Does anyone know if there's a way to run validate your forms before the modal renders?
In actions, schema() runs first before action(), however, I need my form to be validated first before the modal shows up.
I could pass $livewire in a closure for schema(), and then do
$livewire->validate(), but if a ValidationException occurs, it is not handled the same way as when a ValidationException occur inside action().
If the exception occurs inside action (assuming we don't have a modal), the fields that failed the validation gets highlighted red. But if it as inside schema(), an error log just pops up.
This is my current solution:
- I am using a notification for now as an indicator that the validation failed
- I would prefer if the fields get highlighted red when a ValidaitonException occurs
- I have a notificationSent flag cause for some reason, schema() is called multiple times in quick succession when I click the action.
Context: I don't have much experience with Laravel, Livewire, Filament.Solution:Jump to solution
Just add:
$livewire->setErrorBag($exception->validator->errors()); inside of the catch block.
```php
private static function validate(Page $livewire): void
{...2 Replies
Solution
Just add:
$livewire->setErrorBag($exception->validator->errors()); inside of the catch block.
It stopped working for some reason...