检测到Aurelia验证验证错误,但没有错误消息 [英] Aurelia Validation validation error detected, but no error message

查看:67
本文介绍了检测到Aurelia验证验证错误,但没有错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要验证的代码非常简单:

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>

使用以下视图模型

 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;
});

现在我大部分时间都可以使用它了,并且在提交检查,文本框轮廓颜色更改等方面,验证显示为false,但是它没有将验证错误消息注入DOM.也没有任何脚本错误消息,如何解决此问题?

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?

是的,我可以在validationProperties中看到验证消息,但是它们没有写入UI.

Yes, I can see the validation messages in the validationProperties, but they're not written to the UI.

推荐答案

如果您的浏览器允许,请在源代码中找到JSPM软件包,然后放入

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.

此外,您使用的是什么版本的aurelia/aurelia-validation?

Also, what version of aurelia/aurelia-validation are you using?

最后,您在发布之前修改了示例吗?

And finally, did you modify your sample before posting?

`<input value.bind="testField" validate="Description" />`

这两个属性是矛盾的.它将值绑定到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".

这篇关于检测到Aurelia验证验证错误,但没有错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆