Skip to content

Add BeforeFormValidateEvent for new and edit actions#7522

Open
Amoifr wants to merge 2 commits intoEasyCorp:5.xfrom
Amoifr:add_before_form_validate_event
Open

Add BeforeFormValidateEvent for new and edit actions#7522
Amoifr wants to merge 2 commits intoEasyCorp:5.xfrom
Amoifr:add_before_form_validate_event

Conversation

@Amoifr
Copy link
Copy Markdown

@Amoifr Amoifr commented Mar 25, 2026

Summary

Add a new BeforeFormValidateEvent dispatched after $form->handleRequest() but before $form->isValid().

Use cases:

  • Perform complex cross-field validation not easily handled by Constraints
  • Return a custom Response (e.g., for AJAX/Vue integrations)
  • Modify entity or form data dynamically before validation runs

Usage example:

use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeFormValidateEvent;

#[AsEventListener]
public function onBeforeFormValidate(BeforeFormValidateEvent $event): void
{
    $entity = $event->getEntityInstance();
    $form = $event->getForm();
    
    // Custom validation logic
    if ($someCondition) {
        $event->setResponse(new JsonResponse(['error' => 'Custom error']));
    }
}

Changes

  • New BeforeFormValidateEvent class extending AbstractLifecycleEvent with StoppableEventTrait
  • Event dispatched in AbstractCrudController::new() and edit() actions

Test plan

  • Manual testing with an event listener
  • Verify existing new/edit flows still work

Fix #7509

Add a new event dispatched after form submission but before validation.
This allows developers to:
- Perform complex cross-field validation
- Return a custom Response (e.g., for AJAX integrations)
- Modify entity or form data before validation runs

The event is dispatched in both new() and edit() actions.

Fix EasyCorp#7509
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add BeforeFormValidateEvent to New/Edit Controllers

1 participant