stimulus-bridge icon indicating copy to clipboard operation
stimulus-bridge copied to clipboard

Controller declaration order matters ?

Open Wait4Code opened this issue 2 years ago • 0 comments

After upgrading to v3.2.2, i've noticed that declaration order of stimulus controllers in HTML matters. In my project I'm using symfony/ux-autocomplete and I have a custom controller to override tom-select options rendering. All my controllers are fetch in eager mode.

Here is an example :

<select id="new_link_sap_order_item" class="form-control" required
        {{ stimulus_controller({
            'symfony/ux-autocomplete/autocomplete':{
                url: path('colporteur_find_sap_order_lines')
            },
            'colporteur--sap-order-item-select':{},
        }) }}>
</select>

Not declaring colporteur--sap-order-item-select before symfony/ux-autocomplete/autocomplete in the HTML, leads to custom controller connecting but never intercepting the autocomplete:pre-connect event dispatched by ux-autocomplete controller.

Obviously, i've fix this by putting my custom controller in first position :

<select id="new_link_sap_order_item" class="form-control" required
        {{ stimulus_controller({
            'colporteur--sap-order-item-select':{},
            'symfony/ux-autocomplete/autocomplete':{
                url: path('colporteur_find_sap_order_lines')
            }
        }) }}>
</select>

But I do not really like things that depends on declaration order to work. Is this a wanted behaviour ? Maybe I'm opening issue in the wrong repo and should open it on symfony/ux one ?

Wait4Code avatar Aug 23 '23 09:08 Wait4Code