Stimulus: Support for multiple data-targets?

Created on 26 Jan 2018  路  1Comment  路  Source: hotwired/stimulus

Hi Basecamp people,

Thank you for this well-thought, another great JS library first of all.
I am currently using this in building one of our prototype and I was wondering if one element can have multiple data-target attributes.

E.g.,

.notifications data-target="notifications.panel, application.panel"

So that I can access this element from both NotificationsController and ApplicationController.
I know I can achieve my goal with other options (e.g., jQuery selectors), but just curious if there's better "stimulusy" way to achieve this.

Most helpful comment

Yep, just separate the target descriptors by a space in the data-target attribute:

<div class="notifications" data-target="notifications.panel application.panel">

>All comments

Yep, just separate the target descriptors by a space in the data-target attribute:

<div class="notifications" data-target="notifications.panel application.panel">
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jaredcwhite picture jaredcwhite  路  3Comments

paulozoom picture paulozoom  路  4Comments

jenkijo picture jenkijo  路  3Comments

adrienpoly picture adrienpoly  路  3Comments

incompletude picture incompletude  路  3Comments