Created
April 1, 2021 09:34
-
-
Save usutani/d97a0781365984ada335d5e8e3fa541c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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