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
Comments
That would be nice, but we'd like to keep the example code short and sweet for now. Thanks for the suggestion! |
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. |
<!--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}!`
}
} |
Thanks a lot for the example! |
Is this still the answer in 2022 ? |
@matoni109 Currently yes, but there was some development going on in this area. Check out #442 |
#442 looks like a great way forward, thanks for the update |
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!
The text was updated successfully, but these errors were encountered: