是Aurelia Js的新手,我需要验证登录表单(必需和emial)属性。在这里,我使用了aurelia-validation插件。我下面的代码
login.js
import {Router} from 'aurelia-router';
import {
ValidationRules
} from 'aurelia-validation';
export class login{
static inject() { return [Router]; }
attached(){
}
}
ValidationRules
.ensure('login.emial').required()
.withMessage(`\${$displayName} cannot be blank.`);
`
我不知道该如何触发并显示错误消息。
main.js
import $ from 'jquery';
export function configure(aurelia) {
aurelia.use
.defaultBindingLanguage()
.defaultResources()
.developmentLogging()
.router()
.history()
.eventAggregator()
.plugin("aurelia-materialize-css")
.plugin('aurelia-validation')
;
aurelia.start().then(() => aurelia.setRoot());
}
的HTML
<input id="email" type="email" class="validate" value.bind="login.emial">
最佳答案
login.js
import {ValidationRules} from 'aurelia-validation';
export class Login{
email = '';
}
ValidationRules
.ensure('email').required();
login.html
<template>
<input value.bind="email & validate">
</template>
https://gist.run/?id=381fdb1a4b0865a4c25026187db865ce
https://gist.run/?id=1d612b3ae341c7e9c12113e1771988e7