Skip to content

Commit 552e7b4

Browse files
committed
minor #7664 Add an explanation about «constraints» validation (chindit, javiereguiluz)
This PR was submitted for the 3.2 branch but it was merged into the 2.7 branch instead (closes #7664). Discussion ---------- Add an explanation about «constraints» validation Added an explanation about the use of «constraints» in Form Classes and the requirement of «ValidatorExtension» if «constraints» keyword is used. This is currently not explained in doc, nor in Forms, Validation, Custom validation or any other page. Commits ------- c9f1b95 Rewords and minor fixes cb6b2e6 Add an explanation about «constraints» validation
2 parents 1851aa5 + c9f1b95 commit 552e7b4

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

validation.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,29 @@ 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+
Constraints in Form Classes
459+
---------------------------
460+
461+
Constraints can be defined while building the form via the ``constraints`` option
462+
of the form fields::
463+
464+
public function buildForm(FormBuilderInterface $builder, array $options)
465+
{
466+
$builder
467+
->add('myField', TextType::class, array(
468+
'required' => true,
469+
'constraints' => array(new Length(array('min' => 3)))
470+
))
471+
}
472+
473+
The ``constraints`` option is only available when adding the ValidatorExtention
474+
to the formBuilder::
475+
476+
Forms::createFormFactoryBuilder()
477+
->addExtension(new ValidatorExtension(Validation::createValidator()))
478+
->getFormFactory()
479+
;
480+
458481
.. index::
459482
single: Validation; Constraint targets
460483

0 commit comments

Comments
 (0)