Reseting disabled buttons for a submitted form using Stimulus

Hey y’all —

Two quick questions, spinning up a Rails 6.1 project to take a look at Rails for the first time since version 4.

Firstly, I walked through the code on the demo project and have not been able to see how DHH has Stimulus reset the disabled property on the button element when adding a message. Is there special magic for this in Stimulus or do I need to use this.element to find the disabled button and reenable?

Secondarily and less importantly, I’ve seen elsewhere mentioned that there a naming convention for stimulus controllers. With the underscore format for both the data tags and the file, it appears to work. This appears to be correct but is it desirable? Is kebab case preferred?

<%= form_with(model: [@goal_statement.goal_set, @goal_statement], 
		data: { controller: "reset_goal_statement_form", 
			action: "turbo:submit-end->reset_goal_statement_form#reset"}) do |form| %>

My stimulus controller is named:



1 Like

I’m running into the same problem. In some places the submit button is re-enabled, while in other cases it remains disabled. Resetting the form (with this.element.reset()) doesn’t help, but also seems unnecessary in the case where the submit button is re-enabled.

So this might be a bug in rails-ujs

As a work around, adding Rails.enableElement(this.element) to your reset form controller reliably re-enables the submit button by the way. Just keep in mind that this enables all elements within your form. You might want to specify the submit button depending on your use case.