Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcb6b2e6

Browse files
chinditxabbuh
authored andcommitted
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.
1 parent1851aa5 commitcb6b2e6

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

‎validation.rst‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,23 @@ for the constraint or play it safe by always passing in an array of options
460460

461461
.. _validator-constraint-targets:
462462

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+
463480
Constraint Targets
464481
------------------
465482

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp