0

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"/>
     </div>

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

                initialize: function () {
                    this._super();
                    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'
                            };

                            $el.datetimepicker(options);

                            var writable = valueAccessor();
                            if (!ko.isObservable(writable)) {
                                var propWriters = allBindingsAccessor()._ko_property_writers;
                                if (propWriters && propWriters.datetimepicker) {
                                    writable = propWriters.datetimepicker;
                                } else {
                                    return;
                                }
                            }
                            writable($(element).datetimepicker("getDate"));
                        },
                        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());
                                widget.date(date);
                            }
                        }
                    };
                    
                    

                    return this;
                },

How to add custom default date in date picker.

Please help me with this.

0

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.