feat: improved dynamic validation

This commit is contained in:
Björn Fromme
2025-10-31 16:23:06 +01:00
parent a619add4e3
commit 29f415a91f
11 changed files with 143 additions and 292 deletions
@@ -81,9 +81,7 @@ class Step2Controller extends AbstractController
$this->bookingService->saveBookingDto($request, $bookingCreateDto, BookingDto::MODE_CREATE);
// Create validation form
$form = $this->createForm(BookingCreateStep2Type::class, $bookingCreateDto, [
'validation_groups' => ['booking_create'],
]);
$form = $this->createForm(BookingCreateStep2Type::class, $bookingCreateDto);
$form->handleRequest($request);
// Handle form submission
@@ -98,7 +96,7 @@ class Step2Controller extends AbstractController
// Generate cards data with validation state if form was submitted and failed
$cardsData = (true === $form->isSubmitted() && false === $form->isValid())
? $this->participantCardService->getAllCardsDataWithValidation($bookingCreateDto, ['booking_create'])
? $this->participantCardService->getAllCardsDataWithValidation($bookingCreateDto)
: $this->generateAllCardsData($bookingCreateDto);
// Calculate summary data
@@ -150,9 +148,7 @@ class Step2Controller extends AbstractController
$this->enrichWithFreshAvailabilities($bookingDto);
// Create form with booking_context option
$form = $this->createParticipantForm($bookingDto, $index, [
'validation_groups' => ['booking_create'],
]);
$form = $this->createParticipantForm($bookingDto, $index);
$form->handleRequest($request);
@@ -103,9 +103,7 @@ class IndexController extends AbstractController
$mutableData = $this->travelDataService->getMutabilityData($bookingData->dateId);
// Create validation form (same pattern as CreateStep2Controller)
$form = $this->createForm(BookingEditType::class, $bookingDto, [
'validation_groups' => ['booking_edit'],
]);
$form = $this->createForm(BookingEditType::class, $bookingDto);
$form->handleRequest($request);
// Handle form submission (clicking "Buchung aktualisieren")
@@ -155,8 +153,10 @@ class IndexController extends AbstractController
return $this->hxRedirect($request, $this->generateUrl('app_booking_edit', ['id' => $id]));
}
// Generate card data for all participants
$cardsData = $this->participantCardService->getAllCardsData($bookingDto);
// Generate card data for all participants with validation state if form was submitted and failed
$cardsData = (true === $form->isSubmitted() && false === $form->isValid())
? $this->participantCardService->getAllCardsDataWithValidation($bookingDto)
: $this->participantCardService->getAllCardsData($bookingDto);
// Calculate summary data for sidebar
$summary = $this->bookingService->getRoomSummaryAndParticipantCount($bookingDto);
@@ -255,7 +255,6 @@ class IndexController extends AbstractController
// Create form for participant with booking context
$form = $this->createForm(BookingParticipantType::class, $wrapper, [
'booking_context' => $bookingDto,
'validation_groups' => ['booking_edit'],
]);
$form->handleRequest($request);