8000 Added description for the "validation_groups" option by stollr · Pull Request #10514 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

Added description for the "validation_groups" option #10514

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 3 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
Prev Previous commit
Some improvements on validation_groups option
  • Loading branch information
naitsirch committed Nov 15, 2018
commit 6185a261f96beda0dcae7b4d38072b124fe09a78
21 changes: 6 additions & 15 deletions reference/forms/types/options/validation_groups.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ groups will be used by the validator.
< 8000 /td>
For ``null`` the validator will just use the ``Default`` group.

If you specify the groups as array or string they will used by the validator
as they are::
If you specify the groups as an array or string they will be used by the
validator as they are::

public function configureOptions(OptionsResolver $resolver)
{
Expand All @@ -22,7 +22,7 @@ This is equivalent to passing the group as array::

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

The form's data will be :doc:`validated agains all groups </form/validation_groups>`.
The form's data will be :doc:`validated against all given groups </form/validation_groups>`.

If the validation groups depend on the form's data a callable may be passed to
the option. Symfony will then pass the form when calling it::
Expand All @@ -36,21 +36,12 @@ the option. Symfony will then pass the form when calling it::
$resolver->setDefaults(array(
'validation_groups' => function (FormInterface $form) {
$entity = $form->getData();
return $entity->getValidationGroups();

return $entity->isUser() ? array('User') : array('Company');
},
));
}

The class that the form is used for may look like this::

class Account
{
public function getValidationGroups()
{
return $this->isUser() ? array('User') : array('Company');
}
}

.. seealso::

You can read more about this in :doc:`/form/data_based_validation`.
Expand All @@ -64,7 +55,7 @@ The class that the form is used for may look like this::
If you need advanced logic to determine the validation groups have
a l 5184 ook at :doc:`/form/validation_group_service_resolver`.

In some cases, you want to validate your groups by steps. To do this, you
In some cases, you want to validate your groups step by step. To do this, you
can pass a :class:`Symfony\\Component\\Validator\\Constraints\\GroupSequence`
to this option. This enables you to validate against multiple groups,
like when you pass multiple groups in an array, but with the difference that
Expand Down
0