Skip to content

Instantly share code, notes, and snippets.

@fkleuver
Forked from bigopon/index.html
Last active March 3, 2021 02:13
Show Gist options
  • Save fkleuver/3650dc148c2c34d369208a85cdc9005c to your computer and use it in GitHub Desktop.
Save fkleuver/3650dc148c2c34d369208a85cdc9005c to your computer and use it in GitHub Desktop.
ValueConverter and CustomElement Issue 0.7
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dumber Gist</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
<base href="/">
</head>
<!--
Dumber Gist uses dumber bundler, the default bundle file
is /dist/entry-bundle.js.
The starting module is pointed to "main" (data-main attribute on script)
which is your src/main.js.
-->
<body>
<my-app></my-app>
<script src="/dist/entry-bundle.js" data-main="main"></script>
</body>
</html>
{
"dependencies": {
"aurelia": "0.10.0-dev.202102251102"
}
}
<input value.bind="valueIn" input.trigger="handleInput()">
import {bindable, BindingMode} from 'aurelia';
export class FormInput {
@bindable({mode: BindingMode.toView}) valueIn;
@bindable({mode: BindingMode.fromView}) valueOut;
handleInput() {
this.valueOut = this.valueIn;
}
}
import Aurelia from 'aurelia';
import { MyApp } from './my-app';
Aurelia.app(MyApp).start();
<import from="./form-input"></import>
<import from="./proper-case-value-converter"></import>
<p>
<label>First Name</label>
<input value.bind="first_name | properCase">
</p>
<p>
<label>First Name</label>
<form-input value-in.bind="first_name | properCase" value-out.bind="first_name"></form-input>
</p>
export class MyApp {
first_name = '';
}
const reverseLookup = {};
export class ProperCaseValueConverter {
toView(value) {
if (value && typeof value == 'string') {
return capitalize(value);
}
return value;
}
}
function capitalize(str) {
return str.split(' ').map(m => {
if (m && m.length > 1) {
return m[0].toUpperCase() + m.substr(1).toLowerCase();
} else {
return m.toUpperCase();
}
}).join(' ');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment