简体   繁体   English

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

[英]KnockoutJS Validation binding value passed to custom binding?

Using KnockoutJS-Validation, I need to pass to a custom binding whether the field passed validation or not. 使用KnockoutJS-Validation,无论字段是否通过验证,我都需要传递给自定义绑定。 Guessing I need to somehow hook into a KnockoutJS-Validation observable at field level using the allBindingsAccessor parameter but unsure how. 猜测我需要使用allBindingsAccessor参数以某种方式挂接到在字段级别可观察到的KnockoutJS-Validation,但不确定如何进行。

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/ http://jsfiddle.net/hotdiggity/mtwLA/6/

The library adds a obserabler isValid to the observable thats extended 该库将obserabler isValid添加到可观察的thats扩展中

http://jsfiddle.net/MCNU8/ http://jsfiddle.net/MCNU8/

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM