Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Outlet name must be same as controller name #669

Open
tito10047 opened this issue Mar 18, 2023 · 9 comments
Open

Outlet name must be same as controller name #669

tito10047 opened this issue Mar 18, 2023 · 9 comments

Comments

@tito10047
Copy link

in

return element.matches(selector) && controllerAttribute.split(" ").includes(outletName)
is checked , if outlet name is in controller attributes.
its means that outlet name must be same as controller name. Its this correct?

this code dont work because outlet name is diferent as controller name
https://codepen.io/tito100/pen/VwGBmoZ

If its this correct behavior, please add it to documentation.

@chrisdmacrae
Copy link

I lost over 4 hours to this.

This is extremely frustrating behaviour -- the docs don't reflect this logic at all.

@intradayreview
Copy link

It makes sense to work this way, as it ensures the correct controller is referenced.

That being said, it caught me too.

@lu-x
Copy link

lu-x commented May 2, 2023

This also got into my way, additionally i'm using namespaced controllers and i cannot make it work.

Example (using Slim here for the markup):

// 'parent'
div data-controller="hello" data-hello-charts--navbar-outlet="#some-id"

// outlet
#some-id data-controller="charts--navbar"

// 'parent' controller outlet definition
static get outlets() { return ['charts--navbar'] }

-> this.chartsNavbarOutlets is always empty

@lu-x
Copy link

lu-x commented May 2, 2023

Nevermind, it works as expected 🎉

@neilmiddleton
Copy link

👋 another person with a couple of hours chasing this. A small edit to the docs should mostly resolve it

@ragboyjr
Copy link

ragboyjr commented Jun 1, 2023

Another one bites the dust :). In my specific example, my outlet target controller was named price-input. It wasn't obvious that value in the outlet definition should have been like: outlets = ['price-input']. I figured it would need to be outlets = ['priceInput'] similar to how targets and values go from dash separated to camel case.

@unikitty37
Copy link

So if the outlet name has to be the same as the controller name, what do we do if we need to have two sets of outlets (with different selectors) on the same controller?

All I can think of is to pass a selector that will pick up both and then do logic to filter the outlets array — but Stimulus should be making life easier for developers, and I really can't see how this restriction does that.

As somebody coming to outlets fairly recently, I can confirm that #679 doesn't give enough detail in the docs to prevent people from getting derailed by this — but I'd favour removing the restriction and letting us give the outlets names that reflect their purpose rather than continually trying to enhance the documentation covering the restriction…

@tacman
Copy link

tacman commented Apr 20, 2024

Like others here, I spent a few hours trying to understand why one outlet worked but not the other. And I thought I read the documentation. This issue title turned out to be the solution.

Outlets are really excellent, easier than dispatching events, but a way to alias the outlet would be most helpful.

@darrynten
Copy link

Please update the docs to show that the outlet name must match the controller, this was hours of debugging for me to finally find this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

9 participants