We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see ourdocumentation.
There was an error while loading.Please reload this page.
1 parent1851aa5 commitcb6b2e6Copy full SHA for cb6b2e6
validation.rst
@@ -460,6 +460,23 @@ for the constraint or play it safe by always passing in an array of options
460
461
.. _validator-constraint-targets:
462
463
+Constraint in Form Classes
464
+------------------
465
+
466
+When creating your own form classes, you may want to add constraint directly in the formBuilder.
467
+This is done by simply adding them as a parameter in your field options::
468
469
+ public function buildForm(FormBuilderInterface $builder, array $options)
470
+ {
471
+ $builder
472
+ ->add('myField', TextType::class, ['required' => true, 'constraints' => [new Length(['min' => 3])]])
473
+ }
474
475
+Please note the *constraints* keyword will only be available if you have
476
+added the *ValidatorExtention* to the formBuilder::
477
478
+ Forms::createFormFactoryBuilder()->addExtension(new ValidatorExtension(Validation::createValidator()))->getFormFactory();
479
480
Constraint Targets
481
------------------
482