How to remove extender from an existing observable?

本小妞迷上赌 提交于 2019-12-03 09:53:26

You can remove all the validation relates properties form an observable which were added by the ko validation with calling:

myObservable.extend({validatable: false});

Or if you want to only remove the required validation you can remove it from the rules collection:

myObservable.rules.remove(function (item) {
        return item.rule == "required";
    });
}

Demo JSFiddle.

But the ko validation has support for conditional validation, so you can specify some condition when the validation should work so maybe this is what you need:

myObservable.extend({
    required: {
        message: "Some message",
        onlyIf: function () { return //some condition; }
    }
});
mikemsq

nemesv answer works with a small typo correction - the function in the remove(...) call should return a boolean value (i.e. '==' instead of '='):

myObservable.rules.remove(function(item) {
  return item.rule == "required";
});

Demo: JSFiddle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!