I have a super simple code I'm trying to validate:
我有一个超级简单的代码,我正在尝试验证:
<template>
<form role="form" submit.delegate="submit()" validate.bind="validation">
<div class="form-group">
<label>Test Field</label>
<input type="text" value.bind="testField" class="form-control" validate="Description" placeholder="What needs to be done?" />
<button type="submit">Submit</button>
</div>
</form>
</template>
With the following viewmodel
使用以下viewmodel
define(["require", "exports", "../scripts/HttpClient", "aurelia-validation", "aurelia-framework"], function(require, exports, HttpClient) {
var AureliaValidation = require('aurelia-validation').Validation;
var MyViewModel = (function () {
function MyViewModel(httpClient, aureliaValidation, isReadyCallback) {
this.httpClient = httpClient;
var self = this;
self.setupValidation(aureliaValidation);
}
MyViewModel.prototype.activate = function (params, queryString, routeConfig) {
};
MyViewModel.prototype.setupValidation = function (validation) {
this.testField = "";
this.validation = validation.on(this).ensure('testField');
//validation
// .on(this.serviceMetadata.ServiceData[0])
// .ensure('Value');
this.validation = this.validation.notEmpty().maxLength(3);
};
MyViewModel.prototype.submit = function () {
debugger;
if (this.validation.checkAll()) {
//Do Something
}
return null;
};
MyViewModel.inject = [HttpClient, AureliaValidation];
return MyViewModel;
})();
return MyViewModel;
});
Now I got it working for the most part, and the validation is showing false on submit check, the textbox outline color changes etc., however it's not injecting the validation error messages into the DOM. There's no script error message either, how can I troubleshoot this?
现在我在大多数情况下都使用它,并且验证在提交检查时显示为false,文本框轮廓颜色更改等,但是它不会将验证错误消息注入DOM。也没有脚本错误消息,我该如何排除故障?
Yes, I can see the validation messages in the validationProperties, but they're not written to the UI.
是的,我可以在validationProperties中看到验证消息,但它们不会写入UI。
1 个解决方案
#1
If your browser allows it, find the JSPM packages in the sources and put a breakpoint here, it's the point where the view strategy looks for labels to append error messages to. If you'd have this code in the open, I'd be happy to have a look for you.
如果您的浏览器允许它,请在源中找到JSPM包并在此处放置一个断点,这是查看策略查找标签以附加错误消息的点。如果您公开使用此代码,我很乐意为您服务。
Also, what version of aurelia/aurelia-validation are you using?
另外,您使用的是什么版本的aurelia / aurelia-validation?
And finally, did you modify your sample before posting?
最后,你是否在发布之前修改了样本?
`<input value.bind="testField" validate="Description" />`
These two attributes are contradictory. It binds the value to testField, but then you use the validate attribute to explicitly show validation messages for property "Description".
这两个属性是矛盾的。它将值绑定到testField,但随后您使用validate属性显式显示属性“Description”的验证消息。
#1
If your browser allows it, find the JSPM packages in the sources and put a breakpoint here, it's the point where the view strategy looks for labels to append error messages to. If you'd have this code in the open, I'd be happy to have a look for you.
如果您的浏览器允许它,请在源中找到JSPM包并在此处放置一个断点,这是查看策略查找标签以附加错误消息的点。如果您公开使用此代码,我很乐意为您服务。
Also, what version of aurelia/aurelia-validation are you using?
另外,您使用的是什么版本的aurelia / aurelia-validation?
And finally, did you modify your sample before posting?
最后,你是否在发布之前修改了样本?
`<input value.bind="testField" validate="Description" />`
These two attributes are contradictory. It binds the value to testField, but then you use the validate attribute to explicitly show validation messages for property "Description".
这两个属性是矛盾的。它将值绑定到testField,但随后您使用validate属性显式显示属性“Description”的验证消息。