hotwired / stimulus-rails

Use Stimulus in your Ruby on Rails app
https://stimulus.hotwired.dev
MIT License
638 stars 92 forks source link

Action params not populating #117

Closed cashmann closed 1 year ago

cashmann commented 1 year ago

I'm having an issue where my Stimulus controller is not picking up event params for a click action. I'm referencing https://stimulus.hotwired.dev/reference/actions#action-parameters to wire this up. Here's a simple setup I have:

View code:

<%= search_form_for @q, url: "#",  html: { data: { controller: "balance form" } } do |f| %>
...
  <tr data-action="click->balance#updateTargetRow" data-balance-id-param="2">
...

Stimulus controller code:

// app/javascript/controllers/balance_controller.js
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {

  updateTargetRow(event) {
    console.log(event.params) //always logs `{}`
    ...
  }
}

Accessing the param via event.currentTarget.dataset.balanceIdParam gives the expected value of "2" in this example. Is this a known issue or do I have something setup wrong?

cashmann commented 1 year ago

Nevermind, I'm an idiot.