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

Clarify how to declare multi-word controller names in docs #62

Closed
joeybeninghove opened this issue Jan 18, 2018 · 8 comments
Closed

Clarify how to declare multi-word controller names in docs #62

joeybeninghove opened this issue Jan 18, 2018 · 8 comments

Comments

@joeybeninghove
Copy link

Just something you might want to add to the docs eventually. After some experimenting with trying to get a multi-word controller working. I eventually realized that it has to be separated by a - instead of a _ like the controller file itself needs to be named.

<div data-controller="option-panel">
  <div data-target="option-panel.widget"></div>
  <div data-action="click->option-panel#show"></div>
</div>

... which points to ...

option_panel_controller.js

At first, I was putting _ in the markup data attributes before I realized it was a dash. This might be assumed by some folks, but still might not be a bad idea to mention it in the docs or in an FAQ somewhere.

I'm happy to submit a pull request for this as well but wasn't sure where or how you'd want to include this in the handbook.

Cheers :)

@sstephenson
Copy link
Contributor

Thank you for the feedback! We do have the webpack filename-to-identifier mapping documented, but I agree it’s not at all obvious. I’d like to see if we can work this into the Handbook.

@joeybeninghove
Copy link
Author

joeybeninghove commented Jan 19, 2018 via email

@geoffdavis92
Copy link

geoffdavis92 commented Jan 19, 2018

Had the same issue with camelCased data attributes for the Data API after the Stimulus render; of course I forgot my HTML5 training, but it may not be obvious to those who may not understand the semantics of data-* attributes.

ex: data-app-showMessage -> data-app-show-message

@javan
Copy link
Contributor

javan commented Jan 19, 2018

Closing for now since this is documented in the installation guide and referenced in the handbook:

Learn how automatic controller loading works in the Installation Guide.

@javan javan closed this as completed Jan 19, 2018
@christhesoul
Copy link

christhesoul commented Jun 3, 2019

Hey @javan. As someone who is struggling a little with this right now, I'd love to help clarify it for other newcomers. Your link above 404s, and I'm struggling to find the right "vanilla" way of doing this.

e.g. Using without a Build System states the following:

application.register("hello", class extends Stimulus.Controller {
  static get targets() {
    return [ "name" ]
  }

  // …
})

Should the "hello" be "hello-world" or "helloWorld"? I feel like it should be helloWorld but I can only get it to work with the data-controller if it's hello-world.

Perhaps it might be clearer if examples were two-word controllers to begin with – as it's (arguably) easier to work backwards from two words than forwards from one?

Happy to help if I can. Thanks. 👍

@javan
Copy link
Contributor

javan commented Jun 3, 2019

@axelerator
Copy link

Hey @javan,
fyi I believe this is also demonstrated in the wrong way in the screen cast..
They reference

data: {controller: "reset_form", action: "turbo:submit-end->reset_form#reset"}

when it really should be

data: {controller: "reset-form", action: "turbo:submit-end->reset-form#reset"}

@sgelbart
Copy link

How about for values from data attributes?

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

7 participants