Aurelia Validation validation error detected, but no error message

泪湿孤枕 提交于 2019-12-11 13:57:25

问题


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

 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?

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


回答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.

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" />`

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".



来源:https://stackoverflow.com/questions/30180765/aurelia-validation-validation-error-detected-but-no-error-message

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!