KnockoutJS验证绑定值传递给自定义绑定?

时间:2014-01-28 12:18:55

标签: javascript jquery validation knockout.js

使用KnockoutJS-Validation,我需要传递给自定义绑定,无论字段是否通过验证。猜测我需要以某种方式使用allBindingsAccessor参数在字段级别挂钩到KnockoutJS-Validation observable但不确定如何。

ko.bindingHandlers.mycustombinding = {
    update: function (element, valueAccessor, allBindingsAccessor) {
        allBindings = allBindingsAccessor(),
        validationObservable = allBindings.validationObservable;    
        if (!validationObservable) {
            //do cool jQuery stuff to the element if it doesn't validate
        }
    }
};

http://jsfiddle.net/hotdiggity/mtwLA/6/

1 个答案:

答案 0 :(得分:1)

库将obserabler isValid添加到扩展的

http://jsfiddle.net/MCNU8/

var observable = ko.observable("f").extend({ number: true });
console.log(observable.isValid());