0

In Continuation of knockout js bind with datetimepicker gives an exception I am now able to use the datetimepicker with knockout but I am unable to use the time picker option of the same tool the code I have tried is embedded into the following jsfiddle but is throwing an error

<code> http://jsfiddle.net/saqibshakil/scdET/ </code> 

check console after edit

4
  • What error do you get ? Commented Jul 22, 2013 at 7:34
  • Your fiddle is 2000 lines long. Ain't nobody got time for that. Commented Jul 22, 2013 at 18:45
  • Tyrius the fiddle is that long because i used the datetimepicker library and as there were no cdn for it i had to paste it in the javascript i will try and find a host Commented Jul 23, 2013 at 5:10
  • Uncaught TypeError: Object [object Object] has no method 'getTimezoneOffset' This is the error Commented Jul 23, 2013 at 5:25

1 Answer 1

3

Looks like calling getDate on timepicker does not return an actual Date.

It appears that you can call it using datetimepicker successfully. So, your binding would look like:

ko.bindingHandlers.timepicker = { init: function (element, valueAccessor, allBindingsAccessor) { //initialize timepicker with some optional options var options = allBindingsAccessor().timepickerOptions || {}; $(element).timepicker(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).timepicker("destroy"); }); }, //update the control when the view model changes update: function (element, valueAccessor) { var value = ko.utils.unwrapObservable(valueAccessor()), current = $(element).datetimepicker("getDate"); if (value - current !== 0) { $(element).datetimepicker("setDate", value); } } }; 

Updated sample: http://jsfiddle.net/rniemeyer/L3BNw/

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.