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
Show file tree
Hide file tree
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
Next Next commit
Added description for the "validation_groups" option
As requested in #4401 a description of the "validation_groups" option of the base ``FormType`` is added.
  • Loading branch information
  • naitsirch committed Nov 15, 2018
    commit d2910ec152e9f3caa57d57832dfff7407116dc53
    3 changes: 3 additions & 0 deletions reference/forms/types/form.rst
    Original file line number Diff line number Diff line change
    Expand Up @@ -34,6 +34,7 @@ on all types for which ``FormType`` is the parent.
    | | - `read_only`_ (deprecated as of 2.8) |
    | | - `required`_ |
    | | - `trim`_ |
    | | - `validation_groups`_ |
    +-----------+--------------------------------------------------------------------+
    | Inherited | - `attr`_ |
    | options | - `auto_initialize`_ |
    Expand Down Expand Up @@ -146,6 +147,8 @@ The actual default value of this option depends on other field options:

    .. include:: /reference/forms/types/options/trim.rst.inc

    .. include:: /reference/forms/types/options/vali 8000 dation_groups.rst.inc

    Inherited Options
    -----------------

    Expand Down
    51 changes: 51 additions & 0 deletions reference/forms/types/options/validation_groups.rst.inc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    validation_groups
    ~~~~~~~~~~~~~~~~~

    **type**: ``array``, ``string``, ``callable`` or ``null`` **default**: ``null``

    This option is only valid on the root form and is used to specify which
    groups will be used by the validator.

    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::

    public function configureOptions(OptionsResolver $resolver)
    {
    $resolver->setDefaults(array(
    'validation_groups' => 'Registration',
    ));
    }

    This is equivalent to passing the group as array::

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

    If the validation groups depend on the form's data a callable may be passed to
    the option. Symfony then will pass the form when calling it::

    use Symfony\Component\Form\FormInterface;

    // ...
    public function configureOptions(OptionsResolver $resolver)
    {
    $resolver->setDefaults(array(
    'validation_groups' => function (FormInterface $form) {
    $entity = $form->getData();
    return $entity->getValidationGroups();
    },
    ));
    }

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

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

    You can read more about this in :doc:`/form/data_based_validation`.
    0