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

Greeting example in demo doesn't react to Enter #129

Closed
merwok opened this issue Mar 21, 2018 · 7 comments
Closed

Greeting example in demo doesn't react to Enter #129

merwok opened this issue Mar 21, 2018 · 7 comments

Comments

@merwok
Copy link

merwok commented Mar 21, 2018

Hello! I was on the project homepage to see what this framework is and tried the «Greet» demo.
Pressing Enter has no effect; one must click on the button. It would be great to have both input methods.
Thanks for considering this!

@javan
Copy link
Contributor

javan commented Mar 22, 2018

That would be nice, but we'd like to keep the example code short and sweet for now. Thanks for the suggestion!

@javan javan closed this as completed Mar 22, 2018
@merwok
Copy link
Author

merwok commented Mar 22, 2018

Ok, too bad. I had hoped that with a modern lib there could be short and sweet code to react to keyboard as well as clicking.

@javan
Copy link
Contributor

javan commented Mar 22, 2018

<!--HTML from anywhere-->
<div data-controller="hello">
  <input data-target="hello.name" data-action="keydown->hello#greetWithKeyboard" type="text">

  <button data-action="click->hello#greet">
    Greet
  </button>

  <span data-target="hello.output">
  </span>
</div>
// hello_controller.js
import { Controller } from "stimulus"

export default class extends Controller {
  static targets = [ "name", "output" ]

  greetWithKeyboard(event) {
    if (event.keyCode == 13) {
      this.greet()
    }
  }

  greet() {
    this.outputTarget.textContent =
      `Hello, ${this.nameTarget.value}!`
  }
}

@merwok
Copy link
Author

merwok commented Mar 22, 2018

Thanks a lot for the example!

@matoni109
Copy link

Is this still the answer in 2022 ?

@marcoroth
Copy link
Member

@matoni109 Currently yes, but there was some development going on in this area. Check out #442

@matoni109
Copy link

#442 looks like a great way forward, thanks for the update

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

4 participants