Last active
January 30, 2018 20:10
-
-
Save kabaehr/2edbd8579faec322f1474a6a9ac126da to your computer and use it in GitHub Desktop.
Event binding
This file contains 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
<template> | |
<h1>Keyboard Events binding example</h1> | |
<div> | |
<span> Keypress event without return true;</span> | |
<input type="text" keypress.delegate="keypress($event)" /> | |
</div> | |
<div> | |
<span> Keypress event with return true; </span> | |
<input type="text" keypress.delegate="keypress2($event)" /> | |
</div> | |
<div> | |
<span> Disallow letter example </span> | |
<input type="text" keypress.delegate="allowOnlyNumbers($event)" /> | |
</div> | |
<div> | |
<span> Disallow letter example with value.bind </span> | |
<input type="text" value.bind="inputValue" keypress.delegate="allowOnlyNumbers($event)" /> | |
</div> | |
InputValue: ${inputValue} | |
</template> |
This file contains 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
export class App { | |
inputValue = 42; | |
keypress($event) { | |
console.log($event); | |
} | |
keypress2($event) { | |
console.log($event); | |
return true; | |
} | |
allowOnlyNumbers($event) { | |
console.log($event); | |
if (event.key.match('[0-9]')) { | |
return true; | |
} | |
} | |
} |
This file contains 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> | |
<title>Aurelia</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="stylesheet" type="text/css" href="main.css"> | |
</head> | |
<body aurelia-app> | |
<h1>Loading...</h1> | |
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/jspm_packages/system.js"></script> | |
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/config.js"></script> | |
<script> | |
System.import('aurelia-bootstrapper'); | |
</script> | |
</body> | |
</html> |
This file contains 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
div { | |
margin-top: 20px; | |
} | |
span { | |
display: block; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment