Skip to content

Instantly share code, notes, and snippets.

@usutani
Created April 1, 2021 09:34
Show Gist options
  • Save usutani/d97a0781365984ada335d5e8e3fa541c to your computer and use it in GitHub Desktop.
Save usutani/d97a0781365984ada335d5e8e3fa541c to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script src="https://unpkg.com/stimulus/dist/stimulus.umd.js"></script>
<script>
(() => {
const application = Stimulus.Application.start()
application.register("checkbox-effects", class extends Stimulus.Controller {
static get targets() {
return ["source", "disable"]
}
connect() {
this.updateDisabledElements()
}
updateDisabledElements() {
this.disableTargets.forEach(element => {
element.disabled = !this.sourceTarget.checked
})
}
})
})()
</script>
</head>
<body>
<div data-controller="checkbox-effects">
<div>
<input data-checkbox-effects-target="source"
data-action="checkbox-effects#updateDisabledElements"
type="checkbox" id="foo" name="foo">
<label for="foo">foo</label>
</div>
<div>
<input data-checkbox-effects-target="disable" type="text" value="bar">
</div>
<div>
<input data-checkbox-effects-target="disable" type="text" value="baz">
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment