i have knockoutjs viewmodel acts "master" viewmodel several modular viewmodels. these modular vm's utilize knockout validated properties own form validations. make these viewmodels validatedobservable
in master viewmodel, can check each if isvalid
true:
function masterviewmodel() { var self = this; self.adduserviewmodel = ko.validatedobservable(new adduserviewmodel()); } function adduserviewmodel() { var self = this; self.username = ko.observable().extend({ required: true }); self.adduser = = function () { if(self.isvalid()) { // perform add user logic here } }.bind(self); }
however, isvalid
method not exist child viewmodel when attempt call it. there issue adding validatedobservable
property function?
the isvalid
added function validatedobservable
, therefore available inside masterviewmodel
.
you use ko.validation.group
when want check if model valid inside model itself:
function adduserviewmodel() { var self = this; self.username = ko.observable().extend({ required: true }); var errors = ko.validation.group(self, { deep: true }); self.adduser = = function () { if (!errors().length) { // perform add user logic here } }; }
Comments
Post a Comment