-
-
Save fkleuver/3650dc148c2c34d369208a85cdc9005c to your computer and use it in GitHub Desktop.
ValueConverter and CustomElement Issue 0.7
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"> | |
| <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> |
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
| { | |
| "dependencies": { | |
| "aurelia": "0.10.0-dev.202102251102" | |
| } | |
| } |
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
| <input value.bind="valueIn" input.trigger="handleInput()"> |
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
| import {bindable, BindingMode} from 'aurelia'; | |
| export class FormInput { | |
| @bindable({mode: BindingMode.toView}) valueIn; | |
| @bindable({mode: BindingMode.fromView}) valueOut; | |
| handleInput() { | |
| this.valueOut = this.valueIn; | |
| } | |
| } |
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
| import Aurelia from 'aurelia'; | |
| import { MyApp } from './my-app'; | |
| Aurelia.app(MyApp).start(); |
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
| <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> |
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
| export class MyApp { | |
| first_name = ''; | |
| } |
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
| 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