For questions regarding the Stimulus Javascript framework
Questions tagged [stimulusjs]
392 questions
5
votes
2 answers
Hotwire Rails - Cannot use import statement outside a module
I have installed hotwire-rails in an existing Rails project. Before even writing any hotwire related code I get the following error on the browser console on every page:
Uncaught SyntaxError: Cannot use import statement outside a module in…

StuartFrost
- 299
- 3
- 9
5
votes
1 answer
Rspec rails hanging after autoload deprecation warning with Stimulus.js
While trying to run RSpec test in rails 6.1.0 with Stimulus.js, I run into an issue where the only output I get from the terminal
EPRECATION WARNING: Initialization autoloaded the constants ApplicationHelper, DashboardHelper, WelcomeHelper,…

Corey Gibson
- 343
- 1
- 17
5
votes
1 answer
Rails 6 Stimulus.js won't run
I have Stimulus.js installed inside of my new Rails 6 app.
Inside of my packs/application.js file, I have the following:
// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to…

dennismonsewicz
- 25,132
- 33
- 116
- 189
5
votes
0 answers
How to define a variable accessible from all methods of the class?
I'm new to JavaScript and probably trying to emulate Ruby with this. I use StimulusJS, but I think the question is applicable to JS in general.
My goal is to run a method (on button click) which would fetch and display all subcategories of the…

sloneorzeszki
- 1,274
- 3
- 12
- 22
4
votes
2 answers
How to register service-worker in rails 7 used importmap?
Updated on 1/18/2023 to reflect the answer from Bijan
Facing problem
I want to convert a web application created with Rails 7 that uses importmap into a PWA.
However, I'm having trouble registering the service-worker using importmap.
I'd appreciate…

mojaomi
- 115
- 6
4
votes
1 answer
ActionController::RoutingError stimulus-loading.js importmap-rails
I'm using Rails 6.1 with @hotwired/stimulus and importmap.
I'm getting this error in dev env.
ActionController::RoutingError (No route matches [GET] "/assets/stimulus-loading.js")
importmap.rb:
pin "application"
pin "@hotwired/stimulus", to:…

dant
- 41
- 2
4
votes
2 answers
How to use stimulus components with rails import maps
I want to include this stimulus component into my brand new rails 7 app:
https://www.stimulus-components.com/docs/stimulus-dropdown
When I follow their setup approach, i get the following error in my browser console:
platforms#:1 Uncaught TypeError:…

Sabrina
- 309
- 1
- 14
4
votes
0 answers
EventListener added to parent div, but event.target becomes children element if clicked on
I'm working with card shaped divs that I need to be clickable. I'm using JS (stimulusJS) to add an EventListener to them so when the user clicks on the card, the event listener is fired adding some CSS classes and populating some hidden fields with…

pinkfloyd90
- 588
- 3
- 17
4
votes
2 answers
Stimulus access action in another controller
Here is one of my Stimulus controllers:
import { Controller } from "@hotwired/stimulus"
import InfiniteScroll from 'infinite-scroll'
export default class extends Controller {
static get targets() {
return ["next", "grid", "footer",…

rctneil
- 7,016
- 10
- 40
- 83
4
votes
1 answer
Use Stimulus Controller in multiple places
I want to be able to use a Stimulus Controller in multiple places in a web app. I want do something like this:
…

Rafael Mora
- 1,095
- 2
- 13
- 21
4
votes
1 answer
Why is my Stimulus JS controller firing twice?
So, I have a Rails application with webpacker, vue, turbolinks and stimulus js installed.
The problem that I am having is that even though the controller is only imported once and even if I temporarily disable turbolinks the initialize() funcition…

Anonymus
- 175
- 14
4
votes
1 answer
how to toggle css attribute with stimulus js
i am having issues targeting css attribute with stimulus.js
i want to toggle display flex to none and flex when i click the icon
display:flex
#css
.dropnav{
display:flex
}
#hide_controller
......
static targets = [ "hide" ]
static classes…

foliwe83
- 546
- 1
- 7
- 24
4
votes
1 answer
Hotwire: How to render two partials for a broadcasted object on to two different pages?
Relatively new to Stimulus and Hotwire and wanted to know,
"Is there a way to render two different partials for the same broadcasted object on two different pages?
I’m trying to render and broadcast an object on a page from one controller to another…

CoderTrack
- 71
- 5
4
votes
1 answer
Fading out removal of element from DOM with Stimulus
I currently have this simple stimulus JS controller which removes an element from DOM
import { Controller } from "stimulus"
export default class extends Controller {
static targets = [ "element" ]
close () {
…

vince
- 2,374
- 4
- 23
- 39
4
votes
2 answers
Stimulus.js way to load a partial?
We are investigating Stimulus.js for use with our Rails6 app and keep hitting conceptual walls in moving our thinking from jQuery to Stimulus.
For example:
On one part of the page we have a button and when that button is clicked we want to load…

phil
- 4,668
- 4
- 33
- 51