Created
October 19, 2017 21:32
-
-
Save ormasoftchile/6f80bf6cbe48c3613904cab7d86aae34 to your computer and use it in GitHub Desktop.
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
<template> | |
<require from="./textbox"></require> | |
<form submit.delegate="submit()"> | |
<ul><li repeat.for="error of controller.errors">${error.message}</li></ul> | |
<textbox value.bind="model.firstName & validate" label="First Name"></textbox> | |
<textbox value.bind="model.lastName & validate" label="Last Name"></textbox> | |
<textbox value.bind="model.email & validate" label="Email"></textbox> | |
<button type="submit">Submit</button> | |
</form> | |
</template> |
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 {inject} from 'aurelia-dependency-injection'; | |
import { | |
ValidationControllerFactory, | |
ValidationController, | |
ValidationRules | |
} from 'aurelia-validation'; | |
@inject(ValidationControllerFactory) | |
export class App { | |
model = { | |
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 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> | |
<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 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 function configure(aurelia) { | |
aurelia.use | |
.standardConfiguration() | |
.developmentLogging() | |
.plugin('aurelia-validation'); | |
aurelia.start().then(() => aurelia.setRoot()); | |
} |
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
<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 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, 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