8000 Rewords and minor fixes · symfony/symfony-docs@c9f1b95 · GitHub
[go: up one dir, main page]

Skip to content

Commit c9f1b95

Browse files
javiereguiluzxabbuh
authored andcommitted
Rewords and minor fixes
1 parent cb6b2e6 commit c9f1b95

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

validation.rst

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -455,27 +455,33 @@ If you're ever unsure of how to specify an option, either check the API document
455455
for the constraint or play it safe by always passing in an array of options
456456
(the first method shown above).
457457

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+
---------------------------
465460

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::
468463

469464
public function buildForm(FormBuilderInterface $builder, array $options)
470465
{
471466
$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+
))
473471
}
474472

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::
477475

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:
479485

480486
Constraint Targets
481487
------------------

0 commit comments

Comments
 (0)
0