Skip to content

[Form] Fix form data related events definition #18587

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

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Changes from all commits
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
21 changes: 8 additions & 13 deletions form/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ A) The ``FormEvents::PRE_SET_DATA`` Event
.........................................

The ``FormEvents::PRE_SET_DATA`` event is dispatched at the beginning of the
``Form::setData()`` method. It can be used to:

* Modify the data given during pre-population;
* Modify a form depending on the pre-populated data (adding or removing fields dynamically).
``Form::setData()`` method. It is used to modify the data given during
pre-population with
:method:`FormEvent::setData() <Symfony\\Component\\Form\\FormEvent::setData>`.
The method :method:`Form::setData() <Symfony\\Component\\Form\\Form::setData>`
is locked since the event is dispatched from it and will throw an exception
if called from a listener.

=============== ========
Data Type Value
Expand All @@ -66,13 +68,6 @@ View data ``null``
See all form events at a glance in the
:ref:`Form Events Information Table <component-form-event-table>`.

.. caution::

During ``FormEvents::PRE_SET_DATA``,
:method:`Form::setData() <Symfony\\Component\\Form\\Form::setData>`
is locked and will throw an exception if used. If you wish to modify
data, you should use
:method:`FormEvent::setData() <Symfony\\Component\\Form\\FormEvent::setData>`
instead.

.. sidebar:: ``FormEvents::PRE_SET_DATA`` in the Form component
Expand All @@ -88,8 +83,8 @@ B) The ``FormEvents::POST_SET_DATA`` Event

The ``FormEvents::POST_SET_DATA`` event is dispatched at the end of the
:method:`Form::setData() <Symfony\\Component\\Form\\Form::setData>`
method. This event is mostly here for reading data after having pre-populated
the form.
method. This event can be used to modify a form depending on the populated data
(adding or removing fields dynamically).

=============== ====================================================
Data Type Value
Expand Down