You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thought I could pass along code I used to bind your addon to controls using Knockoutjs. It's especially useful when binding to a template where the bound item doesn't exist initially.
Thanks
// inspired by http://stackoverflow.com/questions/6612705/knockout-with-jquery-ui-datepicker
// use in Knockoutjs <input data-bind="datetimepicker: myDate, datetimepickerOptions: { minDate: new Date() }" />
(function(window, $, undefined) {
if( window.ko && $.timepicker )
{
ko.bindingHandlers.datetimepicker = {
init: function(element, valueAccessor, allBindingsAccessor) {
//initialize datetimepicker with some optional options
var options = allBindingsAccessor().datetimepickerOptions || {};
$(element).datetimepicker(options);
//handle the field changing
ko.utils.registerEventHandler(element, "change", function () {
var observable = valueAccessor();
observable($(element).datetimepicker("getDate"));
});
//handle disposal (if KO removes by the template binding)
ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
$(element).datetimepicker("destroy");
});
},
update: function(element, valueAccessor) {
var value = ko.utils.unwrapObservable(valueAccessor());
//handle date data coming via json from Microsoft
if (String(value).indexOf('/Date(') == 0) {
value = new Date(parseInt(value.replace(/\/Date\((.*?)\)\//gi, "$1")));
}
current = $(element).datetimepicker("getDate");
if (value - current !== 0) {
$(element).datetimepicker("setDate", value);
}
}
};
}
}(window, jQuery));
The text was updated successfully, but these errors were encountered:
Thought I could pass along code I used to bind your addon to controls using Knockoutjs. It's especially useful when binding to a template where the bound item doesn't exist initially.
Thanks
The text was updated successfully, but these errors were encountered: