validationOptions not working with custom bindingHandlers

别等时光非礼了梦想. 提交于 2019-12-04 05:08:39
Anders

The validation framework have hooks for the value binding, you need to call

ko.validation.makeBindingHandlerValidatable("dateRW");

edit: its not undefined https://jsfiddle.net/it3xl/n7aqjor9/

Looking at the knockout-validation.js source it calls:

makeBindingHandlerValidatable('value') to make the value binding automatically validatable.

You could try adding a call to makeBindingHandlerValidatable to register your handler:

ko.bindingHandlers.dateRW = {
    //dateRW --> the 'read-write' version used both for displaying & updating dates
    init: function (element, valueAccessor, allBindingsAccessor) {
       ...
    },
    update: function (element, valueAccessor, allBindingsAccessor) {
       ...
    }
};

ko.validation.makeBindingHandlerValidatable('dataRW');

validationMessage binding with an empty element.

I don't wanna have the textbox marked in red.
Sometimes it's allowable to use an additional empty markup (span) with the validationMessage binding.

<input data-bind="datepickerCustom: myDate"/>
<span data-bind="validationMessage: myDate" class="validationMessage"></span>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!