more stimulus tests

This commit is contained in:
Ryan W
2023-01-11 22:19:23 -08:00
parent 2d6e6a87fc
commit 96f323a88c
2 changed files with 24 additions and 1 deletions
+10 -1
View File
@@ -1,7 +1,16 @@
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = [ "name", "output" ]
connect() {
this.element.textContent = "Hello World!"
// this.element.textContent = "Hello World!"
console.log('Hello World hello_controller.js');
}
greet() {
console.log('greet');
this.outputTarget.textContent =
`Hello, ${this.nameTarget.value}!`
}
}
+14
View File
@@ -1,3 +1,17 @@
<h1>Welcome</h1>
<%= link_to "Articles", articles_path %>
<h2>Stimulus Check</h2>
<div data-controller="hello">
<input data-hello-target="name" type="text">
<button data-action="click->hello#greet">
Greet
</button>
<span data-hello-target="output">
</span>
</div>