Skip to content

[Live] Dispatch browser events #794

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
Apr 16, 2023

Conversation

weaverryan
Copy link
Member

Q A
Bug fix? no
New feature? yes
Tickets None
License MIT

Hi!

I figured we'd need this eventually :). While building an component that opens/closes a modal, I needed a way to close the modal from a LiveAction in PHP. The way to do that is to dispatch a DOM event from the action, then listen to that with a tiny bit of JavaScript that closes the modal. Modeled after Livewire, like with emit(). Super simple.

Also fixed a bug with attributes.add() on non-live components.

Cheers!

@weaverryan weaverryan force-pushed the live-dispatch-browser-events branch from bfccdfa to e2ca326 Compare April 16, 2023 16:55
@weaverryan weaverryan merged commit 2e2b82d into symfony:2.x Apr 16, 2023
@weaverryan weaverryan deleted the live-dispatch-browser-events branch April 16, 2023 23:13

.. code-block:: html+twig

<div class="modal fade" {{ stimulus_controller('bootstrap-modal') }}">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant quote at the end?

Copy link
Member Author

@weaverryan weaverryan Apr 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely - thanks for mentioning that :) - fixed in an upcoming PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants