Created
August 28, 2016 16:20
-
-
Save jdanyow/06bda9ac6e068ad21dab7b470f69c566 to your computer and use it in GitHub Desktop.
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> | |
<require from="./textbox"></require> | |
<form submit.delegate="submit()"> | |
<ul><li repeat.for="error of controller.errors">${error.message}</li></ul> | |
<textbox value.bind="firstName & validate" label="First Name"></textbox> | |
<textbox value.bind="lastName & validate" label="Last Name"></textbox> | |
<textbox value.bind="email & validate" label="Email"></textbox> | |
<button type="submit">Submit</button> | |
</form> | |
</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
import {inject} from 'aurelia-dependency-injection'; | |
import { | |
ValidationControllerFactory, | |
ValidationController, | |
ValidationRules | |
} from 'aurelia-validation'; | |
@inject(ValidationControllerFactory) | |
export class App { | |
firstName = ''; | |
lastName = ''; | |
email = ''; | |
controller = null; | |
constructor(controllerFactory) { | |
this.controller = controllerFactory.createForCurrentScope(); | |
} | |
submit() { | |
this.controller.validate(); | |
} | |
} | |
ValidationRules | |
.ensure(a => a.firstName).required() | |
.ensure(a => a.lastName).required() | |
.ensure(a => a.email).required().email() | |
.on(App); |
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"> | |
</head> | |
<body aurelia-app="main" class="container"> | |
<h1>Loading...</h1> | |
<script src="https://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/config.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/bundles/babel.js"></script> | |
<script> | |
require(['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
export function configure(aurelia) { | |
aurelia.use | |
.standardConfiguration() | |
.developmentLogging() | |
.plugin('aurelia-validation'); | |
aurelia.start().then(() => aurelia.setRoot()); | |
} |
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> | |
<div class="form-field"> | |
<div class="form-field__label"> | |
${label} | |
<input name.bind="name" | |
id.bind="name" | |
class="form-field__input" | |
type.bind="type" | |
value.bind="value" | |
tabindex.bind="tabIndex" | |
blur.trigger="blur()"> | |
</div> | |
</div> | |
</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
import {bindable, bindingMode, DOM, inject} from 'aurelia-framework'; | |
@inject(Element) | |
export class Textbox { | |
@bindable({defaultBindingMode: bindingMode.twoWay}) value: string; | |
@bindable label: string; | |
@bindable type: string = "textbox"; | |
@bindable tabIndex: number; | |
@bindable hidden: boolean; | |
@bindable name: string = ''; | |
element: Element; | |
constructor(element) { | |
this.element = element; | |
} | |
blur() { | |
this.element.dispatchEvent(DOM.createCustomEvent('blur')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment