Question

I have included :

knockout.3.0.1.js

knockout.validation.debug.js

jquery.validate.js

Error is : (From Firebug)

TypeError: self.errors is not a function

Except validation all other code is perfect.

My Code

var UserViewModel = function (UserName, Password) {
    var self = this;

    self.UserName = ko.observable(UserName).extend({
        required: {
            message:"Please enter User Name"
        }
    });
    self.Password = ko.observable(Password).extend({
        required: {
            message: "Please enter Password"
        }
    });


    this.loginClick = function () {

        if (self.errors().length == 0)
        {
            alert('no errors');
          //  var strJSON = ko.toJSON(self); //Convert whole model to json
        }
        else
        {
            alert("Please check your submission");
            self.errors.showAllMessages();
        }
        alert("function called");

    };
};

ko.applyBindings(new UserViewModel('', ''));
Was it helpful?

Solution

You forgot to create validation group:

this.errors = ko.validation.group(self);

create validation group, the error will be solved

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top