I have added a date-time picker in my custom form using the below code in HTML file.

     <label class="label">Delivery 
     <div class="control">
         <input class="input-text" type="text" data-bind="datetimepicker: true"  name="delivery_date" id="delivery_date_ship" readonly="true"/>

I have added a date-time picker in my custom JS using the below code.

                initialize: function () {
                    ko.bindingHandlers.datetimepicker = {
                        init: function (element, valueAccessor, allBindingsAccessor) {
                            var $el = $(element);
                            //initialize datetimepicker
                            var options = {
                                minDate: 0,
                                showTime: false,
                                showHour: false,
                                showMinute: false,
                                format: 'yy-mm-dd'


                            var writable = valueAccessor();
                            if (!ko.isObservable(writable)) {
                                var propWriters = allBindingsAccessor()._ko_property_writers;
                                if (propWriters && propWriters.datetimepicker) {
                                    writable = propWriters.datetimepicker;
                                } else {
                        update: function (element, valueAccessor) {
                            var widget = $(element).data("DateTimePicker");
                            //when the view model is updated, update the widget
                            if (widget) {
                                var date = ko.utils.unwrapObservable(valueAccessor());

                    return this;

How to add custom default date in date picker.

Please help me with this.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.