Questions tagged [stimulusjs]
The stimulusjs tag has no usage guidance, but it has a tag wiki.
237
questions
1
vote
1
answer
41
views
How do I call a Stimulus controller that's more than one word?
So I've tried
{ controller: "reset_form", action: "turbo:submit-end->reset_form#reset" }
{ controller: "reset-form", action: "turbo:submit-end->reset-form#...
0
votes
0
answers
16
views
How to trigger "Leave Site?" message for single page – Turbo & Stimulus JS
I want to trigger the in-browser message of "Leave Site?" before leaving a specific form on my site (exactly how StackOverflow does it).
The form is at /posts/new (or /posts/xxx/edit).
...
0
votes
0
answers
11
views
Rails 7/Stimulus: Connect() fires twice but why can I only access values on its first firing?
I understand that connect() will fire twice in Rails due to Turbo first loading a cached version of the page.
I have a form model. Within the model I have embedded a Stripe card element.
I am trying ...
0
votes
0
answers
18
views
Ajax callbacks do not fire with jquery_ujs (jquery-rails v4.5.0)
Environment: rails 5.1, stimulus 2.0
I'm trying to bind the ajax callbacks to my stimulus actions in the following code
<%= form_with model: @new_negotiation, html: { data: { remote: true, type: &...
0
votes
1
answer
19
views
Importing other function in Stimulus controller
In a Stimulus controller in Rails 7 I am importing functions from another js file in my /javascript directory
import * as myHelpers from "../helpers/my_helpers.js";
This works fine in ...
0
votes
1
answer
37
views
fire event from external controller
i'm moving to Rails 7 and i feel like there are so many changes but i'm confident on understanding them and be able to upgrade a personal applications i made myself for keeping my personal records and ...
0
votes
0
answers
58
views
TypeErrror: monthSelectPlugin is not a constructor when attempting to use Flatpickr plugin
I am attempting to use the monthSelectPlugin for flatpickr within a rails app. I have it pinned in my importmap like so:
pin "flatpickr/dist/plugins/monthSelect", to: "https://cdn....
-1
votes
0
answers
17
views
Check when Stimulus loaded all his controller
Is there an event that I can catch when all the stimulus controllers has been "connected" ?
I'm in a situation that I must run a promise all that collects all the objects instantiated in a ...
0
votes
0
answers
14
views
Rails Stimulus delete resource from DB
I am trying to implement a "delete" action via Stimulus in order to replace the boring JS validation windows with sweetalert2. I have the below code, which results in two errors:
While the ...
1
vote
1
answer
52
views
Rails/Stimulus: What is the best way to get form field values when handling form submission with Stimulus?
I have a form but Stimulus will handle its submission.
<%= form_with model: @booking, data: { controller: 'booking', action: 'booking#submitForm:prevent' } do |form| %>
<%= form.text_field :...
0
votes
2
answers
36
views
flash messages with stimulus.js and animate.css
I have a Rails 7 web app that is using Tailwind CSS, Stimulus.js, and animate.css. I have flash messages setup in Rails and I'm trying to add a fadeIn and FadeOut animation. The message will appear ...
0
votes
1
answer
34
views
How to use disconnect() to close a Uppy JS instance – Stimulus
When I click the "back button", my Uppy form is briefly loaded twice. How can I get Stimulus to close the previous Uppy instance when I leave the page?
Following the Uppy Docs, I'm hoping ...
0
votes
0
answers
30
views
span textContent not getting updated
I am trying to update the text of span element from stimulus controller. The event will be fired on data action.
_updateSelectedDealTitle(replace_text){
const ele = document.getElementById('...
1
vote
1
answer
55
views
How to include both a class and data attributes in a form select in Rails 7?
In my Rails 7 app, I am using Stimulus and need to add data attributes to a form select to link it to a JavaScript controller. I am also trying to format the field (not the options) with a class.
Here ...
0
votes
0
answers
11
views
Rails 7 : Multiple forms/buttons on one page, each one supposed to trigger same action but with different input, always triggers the first in list
Here's the issue I'm facing.
I'm creating miniature cards for my models, iterate on every item of the collection (using render @models) and each one has a button to trigger a form (POST) that goes to ...
0
votes
0
answers
34
views
Dropdown list of Humberger button in Rails 7 + Stimulus not correct working in production (mobile)
There is no problem in the development environment, but when operating from a smartphone in the production environment, touches other than the hamburger menu button doesn't work correctly.
The code of ...
0
votes
1
answer
25
views
How use button_to with params + js changes with Rails 7 [Stimulus reflex]
I want to have these events:
click on a specific button
send some params to a custom controller action
react changing view with js
But I'm using Rails 7 and now we have Hotwire/Stimulus Js to make ...
0
votes
1
answer
38
views
Error while calling method form stimulus controller
I'm trying to call a stimulus controller action when clicking a button. As I'm seeing, the scope is correct, also the name of the method, and the stimulus controller is actually well registered.
Still,...
0
votes
0
answers
41
views
how i can sort rows of twig table by using a Stimulus js controller? ican't use knp paginator sort
<div class="table-responsive">
<table class="table align-middle table-nowrap table-check table-striped " id="sortMe">
<thead class="table-...
0
votes
1
answer
45
views
Rails 7 importmaps fullcalendar 5
I need help with following code:
Rails 7.0.3
view.html.erb
<div id="calendar"></div>
importmap.rb
pin "fullcalendar", to: "https://ga.jspm.io/npm:fullcalendar@5....
0
votes
1
answer
128
views
How automatically load all js controller files in Rails 7 with esbuild as JavaScript bundler
I'm trying to configure Rails 7 app to load all js Stimulus controllers automatically.
I use esbuild as JavaScript bundler.
If we're using Stimulus for Rails together with an import map, the ...
1
vote
1
answer
104
views
Stimulus js Cross Controller events context
I have two, independent, stimulus controllers. One that manages a table and one that is used to trigger a new row for the table.
I have a button on the page that calls the turbo-table-new-row#show ...
0
votes
0
answers
49
views
What is the proper way to include the javascript library in rails 7 that doesn't have an export?
I'm having trouble with importing Jquery in rails 7 using bin/importmap. When I import the Jquery with normal script tag, the code works fine. But when I try to do it using bin/importmap in Stimulus ...
-3
votes
1
answer
41
views
how to fix Nan javascript
when I start to write in the htPrice field, Nan appears in the ttcPrice field, how can i fix this?
calculatTTC() {
const htPrice = parseFloat(this.htpriceTargets[0].value);
const tvaPercent =...
1
vote
1
answer
89
views
How do I convert my Jquery code to a StimulusJS controller Rails 7?
I'm building out a feature to show if the discount code in a text field is valid. I just managed to build it out using Jquery, but now I wanna convert it into a StimulusJS controller. But I'm not ...
0
votes
1
answer
73
views
Stimulus js controller
how do I call a stimulus controller fucntion on page load?
thanks
here is my function in stimulus controller :
hide(event)
{
$(this.testTargets[0].tpggle(event.currentTarget.checked);
}
0
votes
1
answer
47
views
Stimulus Framework - connect() not work when change with javascript
I create a stimulus controller and use on a div element.
Now when change innerHTML of this div element with click on a button, text change but color not change to red and connect() not work.
<div ...
0
votes
1
answer
35
views
Reset file field through stimulus controller
I have a form which is submitted through stimulus controller.
#form.html.haml
= form_with url: my_url, multipart: true, data: { turbo_frame: 'document_table_content', turbo_action: 'advanced' } do |f|
...
0
votes
0
answers
37
views
Rails stimulus-autocomplete Errors - Uncaught Error: Module parse failed - Static Targets
I'm still relatively new to the Rails game, but I was wondering whether anyone could assist with a problem that I have.
I wanted to implement [stimulus-autocomplete][1] into my rails 6 app, but when I ...
0
votes
0
answers
48
views
Rails stimulus one form change for many urls and turbo frames
I am building a dashboard with multiple elements like charts, tables, simple fields with calculated values etc and I want to use Rails7 with stimulus.
In the past I used jQuery so I just created empty ...
0
votes
0
answers
35
views
RoR-STimulus-Fetch-API : how to add something fetched to DB
I am trying to add something I fetched from an API to my RoR DB.
So I have :
my view :
<div data-controller="album">
<form data-album-target = "form"
data-action=&...
0
votes
0
answers
47
views
Can't change input value from javascript but working from chrome debugger console
Recently I am facing a strange issue while using https://github.com/Shopify/draggable
package.
So here is the problem, I am using stimulus js in rails app, and in one of the stimulus controllers I ...
0
votes
1
answer
103
views
Issues regarding Stimulus JS , trying to add buttons which hide/show content on the active page when clicked on
I'm making my first personal project on Ruby on Rails (as well as my first post on Stack Overflow !).
I would like to implement a "productivity" page with dedicated keyboard shortcuts for ...
0
votes
1
answer
143
views
Flash message (Stimulus) is not worked in heroku
I'm working on a personal development application with Rails7+Tailwind, and I implemented the code to delete flash messages in stimulus with reference to a web article.
I'm having trouble solving the ...
0
votes
0
answers
62
views
Rails 7 - Stimulus - external script not loaded during navigation (Klaviyo newsletter form)
I have an issue with a script in my website.
The application is based on RAILS 7 and Stimulus.
I have added an external script in order to generate a simple form to sign-in for a newsletter (it is ...
0
votes
0
answers
222
views
adding dynamic form fields in rails 7 using stimulus JS framework
I am using ruby 3.1.2 and rails 7.0.2
this is gem file
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby "3.1.0"
# ...
0
votes
1
answer
130
views
access static values in a Stimulus Typescript controller with the default settings from Symfony
I'm trying to learn Stimulus with a more or less default install of Symfony6 and Encore, one of the main differences with the default install being that I'm using Typescript.
The Stimulus docs say ...
0
votes
1
answer
166
views
Rails - How to pass data between Rails controller and JavaScript Stimulus controller to dynamically change view
I have a Rails app where I have a search results page, which pulls results based on a user's input from a form.
To simplify the Rails controller method:
def search_results
# [...] ActiveRecord ...
0
votes
0
answers
35
views
Uncaught Error: rails-ujs has already been loaded when calling a Stimulus controller on a field in simple_form
Hello everyone :) I'm building an application with Rails 6.1.6.
I am using select2 with simple_form like this:
<%= f.association :events, input_html: { data: { controller: 'select2' } } %>
My ...
0
votes
1
answer
61
views
Change event from bootstrap-datepicker not picked up by Stimulus js
Is it possible to trigger stimulus js from bootstrap-datepicker?
(I'm using it via bootstrap-datepicker-rails)
In my old jQuery code the changeDate event is triggered no problem:
$(document).on('...
0
votes
0
answers
24
views
listening for tubro_stream.update_all changes?
I have a Stimulus controller that updates an element (the dependent) via a turbo_stream.update_all based on the value of another element (the contributor). I want the dependent to be the contributor ...
0
votes
1
answer
42
views
convert SVG code to format to attach to user in Rails
Essentially, in my app users can create a custom svg element using js (stimulus).
My user.rb model has:
has_one_attached :picture
in my attach_image_controller.js I can access the svg code:
<svg&...
0
votes
0
answers
23
views
rails stimulus calculate time
I have a stimulus component that is supposed to calculate the time spent on a page. When loading it saves to a variable the start time and on the event turbo:before-cache it calculates Date.now()-...
2
votes
1
answer
125
views
StimulusJS how to compute value in parent controller from values in different child controllers (cart -> cart items)
I am building a cart with stimulus. The cart recap page displays multiple cart items. A cart item has a unit price and a quantity.
Each cart item component has a quantity selector, when the quantity ...
0
votes
1
answer
62
views
Javascript code refactor to use in Stimulus controller
How to refactor JS code like this:
const fileInput = document.getElementById('input');
const p = document.querySelector('p');
fileInput.onchange = () => {
const selectedFiles = [...fileInput....
0
votes
1
answer
40
views
Rails Drop-down search database
I have a Model Location.
Each location has a name.
A user is filling out a form in which they must choose a location name.
The drop-down would be too long to be practical.
I'd like it such that I can ...
0
votes
1
answer
675
views
Select a specific Target from a Stimulus Controller
I am looking for a simple and elegant way (a Stimulus-way) to select a specific element from the targets elements form my Stimulus controller.
For example: I have a list of 4 links and 4 paragraphs (...
0
votes
0
answers
181
views
How to implement multiselect checkbox dropdown using stimulus js
I am new to stimulus js so bear with me. Is there any library for stimulus js to implement a multi-select checkbox dropdown? Similar to jquery bootstrap multi-select. I tried to search a lot but didn'...
0
votes
1
answer
18
views
How to run a single-file javascript soundboard app from Rails 7
I have a single-file Javascript soundboard application from app academy. The code works fine, but how do I "wire" it into the Rails 7 server? I'm struggling to bridge my understanding ...
2
votes
1
answer
256
views
How to use and load JS helpers in Stimulus controllers in Rails 7?
I want to import and use functions from my javascript/helpers/functions.js file in my stimulus controllers.
I tried pinning it with:
# importmap.rb
pin_all_from "app/javascript/helpers", ...