Stimulus 1.1.1 to Stimulus 2.0.0 – possible regression

Refactoring tests around JS promise.
March 27, 2020

Stimulus 1.1.1 to Stimulus 2.0.0 – possible regression

Yesterday we talked about how ‘simple’ migrating to stimulus-2.0.0 would be. It is - but you should not be stupid.

The changelog wrote:

CHANGED: Default event for text inputs from change to input

Thinking "wow cool" I disregarded it.

I ran the tests and one of them failed. After 10 minutes of wondering why I went to see what was happening on the development server.

The functionality was simple - you enter your name, then change the focus to the next input field and we generate a username from the name you entered.
Тhe form was refreshing every time I typed a letter - not waiting for me to go to the next input field.

It hit me: “We are using the default event for that field”

The code:

<%= f.text_field :name_attribute, data: { action: "registrations#refreshForm" } %>

What needed to be changed:

<%= f.text_field :name_attribute,
    data: { action: "change->registrations#refreshForm" } %>

Leave a Reply