0

I try to add datepicker in magento 2 checkout page like this:

 ko.bindingHandlers.datepicker = {
            init: function (element, valueAccessor, allBindingsAccessor) {
                var $el = $(element);

                if (Array.isArray(holidays)) {
                  var options = {
                    showOn: 'button',
                    dateFormat:'mm/dd/yy',
                    minDate: calendar.min_date,
                    maxDate: calendar.max_date,
                    numberOfMonths: [1, 1],
                    beforeShowDay: function(date) {
                      var string = $.datepicker.formatDate('mm/dd/yy', calendar.holidays); //line 36 => this one that causes an error
                      return [ array.indexOf(string) == -1 ]
                    }
                  };
                } else {
                  var options = {
                    showOn: 'button',
                    dateFormat:'dd/mm/yy',
                    minDate: calendar.min_date,
                    maxDate: calendar.max_date,
                    numberOfMonths: [1, 1]
                  };
                }
                if (calendar.display_two_months !== false) {
                  options.numberOfMonths = [2, 1];
                } 

                $el.datepicker(options);
                $el.datepicker( "show" );

and i got an error like this:

Uncaught TypeError: Unable to process binding "datepicker: function(){return true }"
Message: date.getMonth is not a function
    at Datepicker.formatDate (datepicker.js:1350)
    at HTMLInputElement.beforeShowDay (shipping-delivery-date.js:36)
    at Datepicker._generateHTML (datepicker.js:1753)
    at Datepicker._updateDatepicker (datepicker.js:781)
    at Datepicker.$.datepicker._updateDatepicker (timepicker.js:1396)
    at Datepicker._showDatepicker (datepicker.js:747)
    at Datepicker.$.datepicker._showDatepicker (calendar.js:542)
    at HTMLInputElement.<anonymous> (datepicker.js:2059)
    at Function.each (jquery.js:376)
    at jQuery.fn.init.each (jquery.js:142)

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.