Skip to content

Commit 083de87

Browse files
committed
Minor tweaks
1 parent 093244f commit 083de87

File tree

2 files changed

+35
-36
lines changed

2 files changed

+35
-36
lines changed

doc/events.rst

+19-20
Original file line numberDiff line numberDiff line change
@@ -80,44 +80,43 @@ property of the ``BlogPost`` entity before persisting it:
8080
JavaScript Events
8181
-----------------
8282

83-
EasyAdmin triggers some `JavaScript events`_ when the user interacts with entity forms:
83+
EasyAdmin triggers several `JavaScript events`_ during user interactions with entity forms:
8484

8585
================================ ============================================== ================================ ==========
8686
Event type Occurs when Event detail Cancelable
8787
================================ ============================================== ================================ ==========
8888
``'ea.form.error'`` User submits a form that has validation errors ``{page: pageName, form: form}`` true
89-
-------------------------------- ---------------------------------------------- -------------------------- ----------
89+
-------------------------------- ---------------------------------------------- -------------------------- ----------
9090
``'ea.form.submit'`` User submits a form ``{page: pageName, form: form}`` true
9191
-------------------------------- ---------------------------------------------- -------------------------------- ----------
9292
``'ea.collection.item-added'`` Item added to collection ``{newElement: element}`` false
9393
-------------------------------- ---------------------------------------------- -------------------------------- ----------
9494
``'ea.collection.item-removed'`` Item removed from collection false
9595
================================ ============================================== ================================ ==========
9696

97-
(see `CustomEvent: detail property
98-
<https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/detail>`_ for
99-
details on "Event detail" and `Event: cancelable property
100-
<https://developer.mozilla.org/en-US/docs/Web/API/Event/cancelable>`_ for
101-
details on "Cancelable".)
97+
.. tip::
10298

103-
Example usage:
99+
Read more about the `detail property`_ and the `cancelable property`_
100+
of JavaScript events.
104101

105-
.. code-block:: javascript
102+
Here's how you can listen for these events in JavaScript:
106103

107-
document.addEventListener('ea.form.error', (event) => {
108-
const {page, form} = event.detail
109-
alert(`The ${page} form contains errors. Please resolve these before submitting again.`)
110-
})
104+
.. code-block:: javascript
111105
112-
document.addEventListener('ea.form.submit', (event) => {
113-
const {page, form} = event.detail
114-
console.debug(`${page} form submitted`, form)
115-
})
106+
document.addEventListener('ea.form.error', (event) => {
107+
const {page, form} = event.detail
108+
alert(`The ${page} form contains errors. Please resolve these before submitting again.`)
109+
});
116110
117-
See :doc:`Collection Field JavaScript Events
118-
</fields/CollectionField#javascript-events>` for details on and example use of
119-
the ``'ea.collection.*'`` events.
111+
document.addEventListener('ea.form.submit', (event) => {
112+
const {page, form} = event.detail
113+
console.debug(`${page} form submitted`, form)
114+
});
120115
116+
For more details and examples of the ``ea.collection.*`` events, see the
117+
:doc:`Collection Field JavaScript Events </fields/CollectionField#javascript-events>` section.
121118

122119
.. _`Symfony events`: https://symfony.com/doc/current/event_dispatcher.html
123120
.. _`JavaScript events`: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events
121+
.. _`detail property`: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/detail
122+
.. _`cancelable property`: https://developer.mozilla.org/en-US/docs/Web/API/Event/cancelable

doc/fields/CollectionField.rst

+16-16
Original file line numberDiff line numberDiff line change
@@ -198,27 +198,27 @@ class name of the controller as the first argument::
198198
JavaScript Events
199199
-----------------
200200

201-
When an item is added to a collection field, a `CustomEvent
202-
<https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent>`_ with type
203-
``'ea.collection.item-added'`` is dispatched, and when an item is removed, an
204-
`Event <https://developer.mozilla.org/en-US/docs/Web/API/Event/Event>`_ with
205-
type ``'ea.collection.item-removed'`` dispatched.
201+
When an item is added to a collection field, a `CustomEvent`_ with the type
202+
``'ea.collection.item-added'`` is dispatched. Similarly, when an item is removed,
203+
an `Event`_ with the type ``'ea.collection.item-removed'`` is dispatched.
206204

207205
The ``'ea.collection.item-added'`` event contains information about the added
208-
item in the `detail property
209-
<https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/detail>`_:
206+
item in the `detail property`_:
210207

211-
.. code-block:: javascript
208+
.. code-block:: javascript
212209
213-
document.addEventListener('ea.collection.item-added', (event) => {
214-
const {newElement} = event.detail
215-
console.debug(newElement, 'added to collection')
216-
})
210+
document.addEventListener('ea.collection.item-added', (event) => {
211+
const {newElement} = event.detail
212+
console.debug(newElement, 'added to collection')
213+
});
217214
218-
document.addEventListener('ea.collection.item-removed', (event) => {
219-
// Do something with the event
220-
console.debug('item removed from collection')
221-
})
215+
document.addEventListener('ea.collection.item-removed', (event) => {
216+
// Do something with the event
217+
console.debug('item removed from collection')
218+
});
222219
223220
.. _`CollectionType`: https://symfony.com/doc/current/reference/forms/types/collection.html
224221
.. _`documentation about Symfony CollectionType options`: https://symfony.com/doc/current/reference/forms/types/collection.html#field-options
222+
.. _`CustomEvent`: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent
223+
.. _`Event`: https://developer.mozilla.org/en-US/docs/Web/API/Event/Event
224+
.. _`detail property`: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/detail

0 commit comments

Comments
 (0)