0

我正在尝试进行淘汰赛,但无法使用淘汰赛验证插件进行验证。[编辑:更新小提琴]示例小提琴:jsfiddle.net/EHDD8

           var CustVM = function () {
        var self = this;
        self.name = ko.observable().extend({ required: "Name is required" });
        self.contact = ko.observable();
        self.phone1 = ko.observable();
        self.email = ko.observable().extend({email: true});
        self.website = ko.observable().extend({required: "Website is required"});

        self.Errors = ko.validation.group(self);

         self.save = function () {
            if (self.isValid()) {
                alert("no error");
            }
            else {
                alert("error");
            }
            alert("save clicked ");
        };

        self.cancel = function() {
            alert("cancel clicked");
        };
    };

    ko.applyBindings(new CustVM());

即使我没有输入任何必需的元素,isValid 也是如此。

4

1 回答 1

1

你没有使用

ko.validation.registerExtenders();

这就是您遇到问题的原因,您可以查看我的这篇文章:-

http://www.c-sharpcorner.com/UploadFile/cd7c2e/apply-knockout-validations-in-mvc-application/

于 2013-11-15T03:58:23.953 回答