8000 Add an explanation about «constraints» validation by chindit · Pull Request #7664 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

Add an explanation about «constraints» validation #7664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
chindit authored Mar 22, 2017
commit 70833ef53ad01b3fb4ed904b12b55989fd3afbeb
17 changes: 17 additions & 0 deletions validation.rst
7E93
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,23 @@ for the constraint or play it safe by always passing in an array of options

.. _validator-constraint-targets:

Constraint in Form Classes
------------------

When creating your own form classes, you may want to add constraint directly in the formBuilder.
This is done by simply adding them as a parameter in your field options::

public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('myField', TextType::class, ['required' => true, 'constraints' => [new Length(['min' => 3])]])
}

Please note the *constraints* keyword will only be available if you have
added the *ValidatorExtention* to the formBuilder::

Forms::createFormFactoryBuilder()->addExtension(new ValidatorExtension(Validation::createValidator()))->getFormFactory();

Constraint Targets
------------------

Expand Down
0