Dynamically enable / disable kendo datepicker using Knockout-Kendo.js

I am trying to enable / disable the kendo datepicker based on the selected select value using Knockout-Kendo.js.

HTML:

<select data-bind="value: test">
    <option value="1">1</option>
    <option value="2">2</option>
</select>
<input data-bind="kendoDatePicker: {value: date, enabled: test() == 2}" />

JS:

ko.applyBindings({
    date: ko.observable(),
    test: ko.observable(), 
});

Violin: http://jsfiddle.net/xTjqH/2/

It initially disables the datepicker parameter, but it will not enable it after selecting "2".

+3
source share
1 answer

Depending on how dependencies are tracked for individual parameters in kendo bindings, you will need to present your condition enabledwith the calculated one. Otherwise, the value test() == 2is evaluated immediately and never again.

dateEnabled:

var viewModel = {
    date: ko.observable(),
    test: ko.observable(), 
};

viewModel.dateEnabled = ko.computed(function() {
   return viewModel.test() === "2"; 
});

: http://jsfiddle.net/rniemeyer/JaVKt/

+3

Source: https://habr.com/ru/post/1523931/


All Articles