Skip to content

Add {{ stimulus_action }} / {{ stimulus_target }} #119

@zmitic

Description

@zmitic

{{ stimulus_controller() }} is a great way to assign values to controller but targets and actions requires fallback to long syntax.

Can we have something like this:

<div {{ stimulus_controller('pages/reports/table') }}>

    <a {{ stimulus_action('pages/reports/table', 'onClick') }}>Click me</a>
    <span {{ stimulus_target('pages/reports/table', 'results') }}>results here</span>

</div>

Otherwise, we have to write something like this:

<div {{ stimulus_controller('pages/reports/table') }}>

    <a data-action="pages--reports--table#onClick">Click me</a>
    <span data-pages--reports--table-target="results">results here</span>

</div>

which is harder to write. Having those 2 extensions would also allow easier moving/renaming controllers; users would only need to find 'pages/reports/table' and replace with 'pages/zones/table-advanced'.


{{ stimulus_action('pages/reports/table', 'onClick') }} would also allow third parameter when non-default event is used:

<a {{ stimulus_action('pages/reports/table', 'onNonDefaultEvent', 'hover') }}>Hover me</a>

which would generate

<a data-action="hover->pages--reports--table#onNonDefaultEvent">Hover me</a>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions