0

I am trying to set this date as default date in jQuery UI Datepicker 2014-03-13T18:30:00.000Z

I am using JQueryUI datepicker KO binding handler for that. But it is showing wrong JSON date in textbox where the text is bound.

It is showing 10/23/2019 instead of 2014-03-13..

http://jsfiddle.net/rahulrulez/AkBUv/213/

How to parse it in correct format if there is any?

Rahul Patil
  • 5,656
  • 6
  • 37
  • 65
  • It is problem of ko.toJSON instead of this try ko.toJS – Akhlesh Mar 14 '14 at 07:03
  • How can it be problem with ko.toJSON mate. Date is showing as 10/23/2019 instead of 2014-03-13 – Rahul Patil Mar 14 '14 at 07:19
  • 2
    Actually there are different problem which i have seen that after updating the value it showing 1 less then original. and in your case when you are giving hard coded date it is not parsing it correctly so do one thing add this in binding under update var value = ko.utils.unwrapObservable(valueAccessor()), value=new Date(value); – Akhlesh Mar 14 '14 at 07:27

1 Answers1

1

This is (indirectly) a duplicate of jQuery UI DatePicker - Change Date Format

To solve your specific example, change your input data-bind expression to

<input data-bind="datepicker: newDate, datepickerOptions: { dateFormat: 'yy-mm-dd' }" />

Your datepicker binding reads the datepickerOptions binding to supplies that object as options to the $.datepicker call.

var options = allBindingsAccessor().datepickerOptions || {};

Be careful when you upgrade to knockout 3.x as the allBindingAccessor has changed. More details from KO's doco -> Creating custom bindings

Community
  • 1
  • 1
Robert Slaney
  • 3,712
  • 1
  • 21
  • 25