8000 Added doc about usage of GroupSequence and links to related articles … · symfony/symfony-docs@9b6b757 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9b6b757

Browse files
author
naitsirch
committed
Added doc about usage of GroupSequence and links to related articles for form option 'validation_groups'
1 parent 4beff1e commit 9b6b757

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

reference/forms/types/options/validation_groups.rst.inc

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
validation_groups
22
~~~~~~~~~~~~~~~~~
33

4-
**type**: ``array``, ``string``, ``callable`` or ``null`` **default**: ``null``
4+
**type**: ``array``, ``string``, ``callable``, :class:`Symfony\\Component\\Validator\\Constraints\\GroupSequence` or ``null`` **default**: ``null``
55

66
This option is only valid on the root form and is used to specify which
77
groups will be used by the validator.
@@ -22,10 +22,13 @@ This is equivalent to passing the group as array::
2222

2323
'validation_groups' => array('Registration'),
2424

25+
The form's data will be :doc:`validated agains all groups </form/validation_groups>`.
26+
2527
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::
2729

2830
use Symfony\Component\Form\FormInterface;
31+
use Symfony\Component\OptionsResolver\OptionsResolver;
2932

3033
// ...
3134
public function configureOptions(OptionsResolver $resolver)
@@ -48,4 +51,41 @@ The class that the form is used for may look like this::
4851
}
4952
}
5053

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

Comments
 (0)
0