Skip to content

Commit

Permalink
Merge branch '7.2' into 7.3
Browse files Browse the repository at this point in the history
* 7.2:
  wrap multiple constraints in a Collection constraint to validate array-like data
  • Loading branch information
javiereguiluz committed Jan 9, 2025
2 parents fb028aa + 0a76498 commit 398663b
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions form/without_class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ This can be done by setting the ``constraints`` option in the
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Collection;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;

Expand All @@ -149,17 +150,15 @@ This can be done by setting the ``constraints`` option in the

public function configureOptions(OptionsResolver $resolver): void
{
$constraints = [
'firstName' => new Length(['min' => 3]),
'lastName' => [
new NotBlank(),
new Length(['min' => 3]),
],
];

$resolver->setDefaults([
'data_class' => null,
'constraints' => $constraints,
'constraints' => new Collection([
'firstName' => new Length(['min' => 3]),
'lastName' => [
new NotBlank(),
new Length(['min' => 3]),
],
]),
]);
}

Expand Down

0 comments on commit 398663b

Please sign in to comment.