Reputation: 1
I want to see a message in the console once I change the select value. I'm using Hotwire and Rails 7 but it doesn't work.
<%= form_with model: [@framework, @framework.criteria.build] do |form| %>
<div>
<%= form.label :criteria_name %>
<%= form.text_field :criteria_name, class: "rounded-md border border-pbgray-medium w-full mb-2" %>
</div>
<div data-controller="answer">
<div>
<%= form.label :type_answer %>
<%= form.select :type_answer, [["Multiple Choice", 1], ["Single choice", 2], ["Text-box", 3]], {data: { action: "change->answer#my_method"}} %>
</div>
</div>
<p data-action="click->answer#my_method">Click me!!</p>
<div>
<%= form.submit %>
</div>
<% end %>
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
my_method() {
console.log("Hello new World");
}
}
Upvotes: 0
Views: 1155
Reputation: 1
Nevermind, I found the issue:
<%= form.select(:type_answer, [["Multiple choice", 1], ["Text-box", 2]], {}, { :class => 'some-class', :data => {:action => "click->answer#my_method"} }) %>
Upvotes: 0