Skip to content

Instantly share code, notes, and snippets.

@fkleuver
Last active March 3, 2021 02:23
Show Gist options
  • Save fkleuver/84e33c5e6ad8a9cc66eef32303abce9e to your computer and use it in GitHub Desktop.
Save fkleuver/84e33c5e6ad8a9cc66eef32303abce9e 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="_value" input.trigger="value = _value">
import {bindable, BindingMode} from 'aurelia';
export class FormInput {
@bindable({mode: BindingMode.twoWay}) value;
valueChanged() {
this._value = this.value;
}
}
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.bind="first_name | properCase"></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