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

Appearance settings

Commit 6e71ed0

Browse filesBrowse files
committed
wrap multiple constraints in a Collection constraint to validate array-like data
1 parent 2199b6b commit 6e71ed0
Copy full SHA for 6e71ed0

File tree

Expand file treeCollapse file tree

1 file changed

+8
-9
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+8
-9
lines changed

‎form/without_class.rst

Copy file name to clipboardExpand all lines: form/without_class.rst
+8-9Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ This can be done by setting the ``constraints`` option in the
137137
use Symfony\Component\Form\Extension\Core\Type\TextType;
138138
use Symfony\Component\Form\FormBuilderInterface;
139139
use Symfony\Component\OptionsResolver\OptionsResolver;
140+
use Symfony\Component\Validator\Constraints\Collection;
140141
use Symfony\Component\Validator\Constraints\Length;
141142
use Symfony\Component\Validator\Constraints\NotBlank;
142143

@@ -149,17 +150,15 @@ This can be done by setting the ``constraints`` option in the
149150

150151
public function configureOptions(OptionsResolver $resolver): void
151152
{
152-
$constraints = [
153-
'firstName' => new Length(['min' => 3]),
154-
'lastName' => [
155-
new NotBlank(),
156-
new Length(['min' => 3]),
157-
],
158-
];
159-
160153
$resolver->setDefaults([
161154
'data_class' => null,
162-
'constraints' => $constraints,
155+
'constraints' => new Collection([
156+
'firstName' => new Length(['min' => 3]),
157+
'lastName' => [
158+
new NotBlank(),
159+
new Length(['min' => 3]),
160+
],
161+
]),
163162
]);
164163
}
165164

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.