Search code examples
asynchronousknockout.jsknockout-mapping-pluginknockout-validation

Async validation with Ko.validation and Ko.mapping


Im using ko.validation and ko.mapping to display some data in a table. This data can be editted or more data can be added to the table.

see fiddle: http://fiddle.jshell.net/juandozco/v9L69g8a/5/

Im reusing the form to edit or create this items. My problem is, some of the properties in the items cant be editted, so im hidding those properties in the edit mode, but the validation still happens and doesnt let the form continue.

I tried 3 different things, see lines:

1, 90 and 112 in the javascript section in my fiddle

how can i achieve this validation?


Solution

  • well you need to skip the validation on edit part so you need do add extender like validatable: false on your observable .

    Code :

    self.edit = function (user) {
        self.User().userName.extend({ validatable: false }); // Key here
        self.editing(true);
        ............
        self.User().userName(user.userName());
    };
    

    working sample here