0

I'm trying to work on knockout and unable to validate using knockout validation plugin. [EDIT: update fiddle] sample fiddle: 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 is true even though i have not entered any required elements.

Kalyan
  • 307
  • 2
  • 14
  • Your fiddle is broken because the validation plugin referenced from https://github.com/Knockout-Contrib/Knockout-Validation/blob/master/Src/knockout.validation.jsard/Knockout-Validation/master/Src/knockout.validation.js returns 404 not found error... Here is fiddle: http://jsfiddle.net/EHDD8/ with the fixed plugin and where your code works just fine... – nemesv Aug 25 '13 at 14:41
  • yup, thanks you. not sure why, but this works great in fiddle and not when i moved all this to asp.net MVC4 project and working in firefox. any ideas on it? knockout and validation plugin in are part of the page. – Kalyan Aug 25 '13 at 15:07
  • Bit of a guessing game for us why it doesn't work in your specific situation, because we have no access to or way to repro that situation. Please try to find the root cause (if all else fails, use [binary debugging](http://programmers.stackexchange.com/a/181223/40625)) and get back to us with an update to the question. – Jeroen Aug 25 '13 at 18:56
  • possible duplicate of [Knockout-validation group error checking](http://stackoverflow.com/questions/19393903/knockout-validation-group-error-checking) – PW Kad Nov 15 '13 at 04:01

1 Answers1

1

You are not using

ko.validation.registerExtenders();

that's why you are having problem, you can check my this ARticle:-

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