Using multiple actions on a single element with Stimulus
This blog post was originally published a little while ago. Please consider that it may no longer be relevant or even accurate.
Sometimes it makes sense to want to fire an event from an element off to multiple controllers (if the element is a child of both controller scopes). Luckily this is something that was considered by the Stimulus team and it works out of the box.
In this example, both
FormController#change would be called with the change event. There are many use-cases for this - in the above example your
EmailController might be looking to validate that email with an external service while a
FormController might be interested in toggling other relevant parts of the form for display.