Skip to content

Instantly share code, notes, and snippets.

@kabaehr
Last active January 30, 2018 20:10
Show Gist options
  • Save kabaehr/2edbd8579faec322f1474a6a9ac126da to your computer and use it in GitHub Desktop.
Save kabaehr/2edbd8579faec322f1474a6a9ac126da to your computer and use it in GitHub Desktop.
Event binding
<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>
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;
}
}
}
<!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>
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