1
1
validation_groups
2
2
~~~~~~~~~~~~~~~~~
3
3
4
- ** type** : ``array``, ``string``, ``callable`` or ``null`` ** default** : ``null``
4
+ ** type** : ``array``, ``string``, ``callable``, :class:`Symfony\\Component\\Validator\\Constraints\\GroupSequence` or ``null`` ** default** : ``null``
5
5
6
6
This option is only valid on the root form and is used to specify which
7
7
groups will be used by the validator.
@@ -22,10 +22,13 @@ This is equivalent to passing the group as array::
22
22
23
23
' validation_groups' = > array (' Registration' ),
24
24
25
+ The form' s data will be :doc:`validated agains all groups </form/validation_groups>`.
26
+
25
27
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::
28
+ the option. Symfony will then pass the form when calling it::
27
29
28
30
use Symfony\Component\Form\FormInterface;
31
+ use Symfony\Component\OptionsResolver\OptionsResolver;
29
32
30
33
// ...
31
34
public function configureOptions (OptionsResolver $resolver )
@@ -48,4 +51,41 @@ The class that the form is used for may look like this::
48
51
}
49
52
}
50
53
51
- You can read more about this in :doc:`/form/data_based_validation`.
54
+ .. seealso::
55
+
56
+ You can read more about this in :doc:`/ form/ data_based_validation`.
57
+
58
+ .. note::
59
+
60
+ When your form contains multiple submit buttons, you can change the
61
+ validation group depending on : doc:`which button is used< / form/ button_based_validation> `
62
+ to submit the form.
63
+
64
+ If you need advanced logic to determine the validation groups have
65
+ a look at : doc:`/ form/ validation_group_service_resolver`.
66
+
67
+ In some cases, you want to validate your groups by steps. To do this , you
68
+ can pass a : class:`Symfony\\Component\\Validator\\Constraints\\GroupSequence`
69
+ to this option. This enables you to validate against multiple groups,
70
+ like when you pass multiple groups in an array, but with the difference that
71
+ a group is only validated if the previous groups pass without errors.
72
+ Here' s an example::
73
+
74
+ use Symfony\Component\Validator\Constraints\GroupSequence;
75
+ use Symfony\Component\Form\AbstractType;
76
+ // ...
77
+
78
+ class MyType extends AbstractType
79
+ {
80
+ // ...
81
+ public function configureOptions(OptionsResolver $resolver)
82
+ {
83
+ $resolver->setDefaults([
84
+ ' validation_groups' => new GroupSequence([' First' , ' Second' ]),
85
+ ]);
86
+ }
87
+ }
88
+
89
+ .. seealso::
90
+
91
+ Read the article :doc:`/validation/sequence_provider` to find out more about this.
0 commit comments