File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ on all types for which ``FormType`` is the parent.
34
34
| | - `read_only `_ (deprecated as of 2.8) |
35
35
| | - `required `_ |
36
36
| | - `trim `_ |
37
+ | | - `validation_groups `_ |
37
38
+-----------+--------------------------------------------------------------------+
38
39
| Inherited | - `attr `_ |
39
40
| options | - `auto_initialize `_ |
@@ -146,6 +147,8 @@ The actual default value of this option depends on other field options:
146
147
147
148
.. include :: /reference/forms/types/options/trim.rst.inc
148
149
150
+ .. include :: /reference/forms/types/options/validation_groups.rst.inc
151
+
149
152
Inherited Options
150
153
-----------------
151
154
Original file line number Diff line number Diff line change
1
+ validation_groups
2
+ ~~~~~~~~~~~~~~~~~
3
+
4
+ ** type** : ``array``, ``string``, ``callable`` or ``null`` ** default** : ``null``
5
+
6
+ This option is only valid on the root form and is used to specify which
7
+ groups will be used by the validator.
8
+
9
+ For ``null`` the validator will just use the ``Default`` group.
10
+
11
+ If you specify the groups as array or string they will used by the validator
12
+ as they are::
13
+
14
+ public function configureOptions (OptionsResolver $resolver )
15
+ {
16
+ $resolver- > setDefaults (array (
17
+ ' validation_groups' = > ' Registration' ,
18
+ ));
19
+ }
20
+
21
+ This is equivalent to passing the group as array::
22
+
23
+ ' validation_groups' = > array (' Registration' ),
24
+
25
+ If the validation groups depend on the form' s data a callable may be passed to
26
+ the option. Symfony then will pass the form when calling it::
27
+
28
+ use Symfony\Component\Form\FormInterface;
29
+
30
+ // ...
31
+ public function configureOptions(OptionsResolver $resolver)
32
+ {
33
+ $resolver->setDefaults(array(
34
+ ' validation_groups' => function (FormInterface $form) {
35
+ $entity = $form->getData();
36
+ return $entity->getValidationGroups();
37
+ },
38
+ ));
39
+ }
40
+
41
+ The class that the form is used for may look like this::
42
+
43
+ class Account
44
+ {
45
+ public function getValidationGroups()
46
+ {
47
+ return $this->isUser() ? array(' User' ) : array(' Company' );
48
+ }
49
+ }
50
+
51
+ You can read more about this in :doc:`/form/data_based_validation`.
You can’t perform that action at this time.
0 commit comments