© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•4mo ago•
4 replies
BerriesAndCream

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()
$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:
  ->schema(function (Page $livewire) {
      static $notificationSent = false;

      if (! self::validate($livewire)) {
          if (! $notificationSent) {
              // Notification object is sent
              $notificationSent = true; 
          }
          return null;
      }
      $notificationSent = false;

      return self::getModalSchema($livewire);
  })

---

  private static function validate(Page $livewire): bool
  {
      try {
          $livewire->validate();
      } catch (ValidationException $exception) {
          // I can't throw it or else the error log pops up
          return false;
      }
      return true;
  }
  ->schema(function (Page $livewire) {
      static $notificationSent = false;

      if (! self::validate($livewire)) {
          if (! $notificationSent) {
              // Notification object is sent
              $notificationSent = true; 
          }
          return null;
      }
      $notificationSent = false;

      return self::getModalSchema($livewire);
  })

---

  private static function validate(Page $livewire): bool
  {
      try {
          $livewire->validate();
      } catch (ValidationException $exception) {
          // I can't throw it or else the error log pops up
          return false;
      }
      return true;
  }

- 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
Just add:
$livewire->setErrorBag($exception->validator->errors());
$livewire->setErrorBag($exception->validator->errors());
inside of the catch block.

  private static function validate(Page $livewire): void
  {
      try {
          $livewire->validate();
      } catch (ValidationException $exception) {
          $livewire->setErrorBag($exception->validator->errors());
      }
  }
  private static function validate(Page $livewire): void
  {
      try {
          $livewire->validate();
      } catch (ValidationException $exception) {
          $livewire->setErrorBag($exception->validator->errors());
      }
  }
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Confirmation modal before action.
FilamentFFilament / ❓┊help
3y ago
Validate and save before opening modal
FilamentFFilament / ❓┊help
2y ago
Open modal before create action
FilamentFFilament / ❓┊help
3y ago
before validate
FilamentFFilament / ❓┊help
2y ago