@@ -455,27 +455,33 @@ If you're ever unsure of how to specify an option, either check the API document
455
455
for the constraint or play it safe by always passing in an array of options
456
456
(the first method shown above).
457
457
458
- .. index ::
459
- single: Validation; Constraint targets
460
-
461
- .. _validator-constraint-targets :
462
-
463
- Constraint in Form Classes
464
- ------------------
458
+ Constraints in Form Classes
459
+ ---------------------------
465
460
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 ::
461
+ Constraints can be defined while building the form via the `` constraints `` option
462
+ of the form fields ::
468
463
469
464
public function buildForm(FormBuilderInterface $builder, array $options)
470
465
{
471
466
$builder
472
- ->add('myField', TextType::class, ['required' => true, 'constraints' => [new Length(['min' => 3])]])
467
+ ->add('myField', TextType::class, array(
468
+ 'required' => true,
469
+ 'constraints' => array(new Length(array('min' => 3)))
470
+ ))
473
471
}
474
472
475
- Please note the * constraints * keyword will only be available if you have
476
- added the * ValidatorExtention * to the formBuilder::
473
+ The `` constraints `` option is only available when adding the ValidatorExtention
474
+ to the formBuilder::
477
475
478
- Forms::createFormFactoryBuilder()->addExtension(new ValidatorExtension(Validation::createValidator()))->getFormFactory();
476
+ Forms::createFormFactoryBuilder()
477
+ ->addExtension(new ValidatorExtension(Validation::createValidator()))
478
+ ->getFormFactory()
479
+ ;
480
+
481
+ .. index ::
482
+ single: Validation; Constraint targets
483
+
484
+ .. _validator-constraint-targets :
479
485
480
486
Constraint Targets
481
487
------------------
0 commit comments