Skip to content

Instantly share code, notes, and snippets.

@Beyarz
Last active March 17, 2022 00:45
Show Gist options
  • Select an option

  • Save Beyarz/0f569ecca4baafeef2b1d4b72648ba0b to your computer and use it in GitHub Desktop.

Select an option

Save Beyarz/0f569ecca4baafeef2b1d4b72648ba0b to your computer and use it in GitHub Desktop.
StimulusJS on CDN
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Stimulus</title>
<script type="module">
import {
Application,
Controller
} from "https://cdn.skypack.dev/@hotwired/stimulus";
window.Stimulus = Application.start();
Stimulus.register(
"preview",
class extends Controller {
static targets = ["inbound", "outbound"];
setValue() {
let value = this.inboundTarget.value;
this.outboundTarget.innerText = value;
}
}
);
</script>
</head>
<body>
<div data-controller="preview">
<label>Input: </label>
<input
data-action="input->preview#setValue"
data-preview-target="inbound"
placeholder="Enter something..."
value=""
type="text"
/>
<p>
You entered:
<span data-preview-target="outbound"></span>
</p>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment