question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using ujs ajax events with stimulus actions

See original GitHub issue

First of all, thank you for Stimulus – it’s great.

I’m wondering if it is possible currently or planned to be able to bind to ujs ajax events with stimulus’s action binding syntax.

I have a modal I want to close on an ajax:success event after the modal’s form is submitted . Placing the data attribute data: {action: 'ajax:success->modal#close'} on the form doesn’t seem to bind, or I haven’t been able to suss out my error.

It’s no problem to bind it manually once the controller is connected, but the action syntax is pretty nifty.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
sstephensoncommented, Jan 31, 2018

As @lsylvester says, you’ll need to make sure to use rails-ujs, which emits regular DOM events instead of jQuery events.

3reactions
lsylvestercommented, Jan 31, 2018

@mmlindeboom Are you using jquery_ujs or rails-ujs UJS adapter? I don’t have any problems listening to ajax:* events when using rails-ujs but I get nothing when using jquery_ujs, I think cause they are jquery events instead of dom events.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using ujs ajax events with stimulus actions · Issue #78 - GitHub
I'm wondering if it is possible currently or planned to be able to bind to ujs ajax events with stimulus's action binding syntax....
Read more >
How to combine Rails's Ajax support and Stimulus
In this post I'm going to explain how we are exploring adding snappier SPA-like interactivity to the Admin and what we've learned so...
Read more >
Stimulus and Rails UJS - Hotwire Discussion
You can use all the rails-ujs request lifecycle events on your actions, so if you need to perform some logic before the request...
Read more >
Stimulus and Ajax. Modern Front-End Development for Rails…
The simplest mechanism for making Ajax calls in modern JavaScript is with the fetch function and the async/await syntax for handling ...
Read more >
Stimulus and Ajax - Modern Front-end Development for Rails
Learn to use Stilumus and Ajax in this lesson. ... The Rails UJS library provides an ajax method, but the fetch function is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found