diff --git a/form/without_class.rst b/form/without_class.rst index 436976bdfcc..c3e1f7c7cc2 100644 --- a/form/without_class.rst +++ b/form/without_class.rst @@ -99,7 +99,8 @@ but here's a short example:: 'constraints' => new Length(['min' => 3]), ]) ->add('lastName', TextType::class, [ - 'constraints' => [ +.. the following configuration triggers an error `An error has occurred resolving the options of the form "Symfony\Component\Form\Extension\Core\Type\FormType": The option "constraints" with value array is expected to be of type "Symfony\Component\Validator\Constraint" or "Symfony\Component\Validator\Constraint[]", but one of the elements is of type "array".` .. + 'constraints' => [ new NotBlank(), new Length(['min' => 3]), ], @@ -166,6 +167,9 @@ This can be done by setting the ``constraints`` option in the This means you can also do this when using the ``createFormBuilder()`` method in your controller:: +.. the following configuration triggers an error `An error has occurred resolving the options of the form "Symfony\Component\Form\Extension\Core\Type\FormType": The option "constraints" with value array is expected to be of type "Symfony\Component\Validator\Constraint" or "Symfony\Component\Validator\Constraint[]", but one of the elements is of type "array".` .. + + $form = $this->createFormBuilder($defaultData, [ 'constraints' => [ 'firstName' => new Length(['min' => 3]),