diff --git a/src/Form/Model/BookingCreateDto.php b/src/Form/Model/BookingCreateDto.php index d2626b2..3a5265a 100644 --- a/src/Form/Model/BookingCreateDto.php +++ b/src/Form/Model/BookingCreateDto.php @@ -4,6 +4,7 @@ namespace App\Form\Model; use App\BusProNet\Model\Travel; use Symfony\Component\Validator\Constraints as Assert; +use Symfony\Component\Validator\Context\ExecutionContextInterface; class BookingCreateDto implements BookingDtoInterface { @@ -49,4 +50,15 @@ class BookingCreateDto implements BookingDtoInterface { return $this->participants[$index] ?? null; } + + #[Assert\Callback(callback: 'validateRoomSelection', groups: ['booking_create_step_1'])] + public function validateRoomSelection(ExecutionContextInterface $context): void + { + $selectedRooms = $this->getSelectedRooms(); + + if (0 === count($selectedRooms)) { + $context->buildViolation('Bitte mindestens ein Zimmer/Bett auswählen') + ->addViolation(); + } + } } diff --git a/templates/booking/create_step_1.html.twig b/templates/booking/create_step_1.html.twig index deedf8e..4d751cd 100644 --- a/templates/booking/create_step_1.html.twig +++ b/templates/booking/create_step_1.html.twig @@ -9,6 +9,7 @@ Unterkunft {{ form_start(form) }} + {{ form_errors(form) }} {% if groupedRooms.by_room is not empty %}