Skip to content

Datepicker binding error in Magento +2.4

I have upgraded from 2.3.7 to 2.4.5 and datepicker binding provokes an error:

jquery.js:4050 jQuery.Deferred exception: Unable to process binding "datepicker: function(){return { storage:dateSelected,options:options} }"
Message: Cannot read properties of undefined (reading 'subscribe') TypeError: Unable to process binding "datepicker: function(){return { storage:dateSelected,options:options} }"
Message: Cannot read properties of undefined (reading 'subscribe')
    at init (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/Hiberus_Appointment/js/lib/knockout/bindings/datepicker.js:59:44)
    at http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/knockoutjs/knockout.js:3730:58
    at Object.ignore (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/knockoutjs/knockout.js:1563:45)
    at http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/knockoutjs/knockout.js:3729:60
    at Object.arrayForEach (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/knockoutjs/knockout.js:168:36)
    at applyBindingsToNodeInternal (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/knockoutjs/knockout.js:3715:34)
    at applyBindingsToNodeAndDescendantsInternal (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/knockoutjs/knockout.js:3573:56)
    at applyBindingsToDescendantsInternal (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/knockoutjs/knockout.js:3555:29)
    at applyBindingsToNodeAndDescendantsInternal (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/knockoutjs/knockout.js:3576:25)
    at applyBindingsToDescendantsInternal (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/knockoutjs/knockout.js:3555:29)
    at applyBindingsToNodeAndDescendantsInternal (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/knockoutjs/knockout.js:3576:25)
    at applyBindingsToDescendantsInternal (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/knockoutjs/knockout.js:3555:29)
    at applyBindingsToNodeAndDescendantsInternal (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/knockoutjs/knockout.js:3576:25)
    at ko.applyBindings (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/knockoutjs/knockout.js:3807:21)
    at _super (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/mage/utils/wrapper.js:73:35)
    at Object.applyBindings (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/Magento_Ui/js/lib/knockout/extender/bound-nodes.js:118:26)
    at Object.applyBindings (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/mage/utils/wrapper.js:78:32)
    at http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/knockoutjs/knockout.js:5870:36
    at invokeForEachNodeInContinuousRange (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/knockoutjs/knockout.js:5821:25)
    at activateBindingsOnContinuousNodeArray (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/knockoutjs/knockout.js:5868:25)
    at executeTemplate (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/knockoutjs/knockout.js:5916:25)
    at ko.dependentObservable.disposeWhen (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/knockoutjs/knockout.js:5962:58)
    at Function.evaluateImmediate_CallReadThenEndDependencyDetection (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/knockoutjs/knockout.js:2331:115)
    at Function.evaluateImmediate_CallReadWithDependencyDetection (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/knockoutjs/knockout.js:2288:41)
    at Function.evaluateImmediate (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/knockoutjs/knockout.js:2253:40)
    at Function.evaluatePossiblyAsync (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/knockoutjs/knockout.js:2218:44)
    at Function.notifySubscribers (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/knockoutjs/knockout.js:1401:50)
    at Function.valueHasMutated (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/knockoutjs/knockout.js:1645:46)
    at UiClass.observable [as nodes] (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/knockoutjs/knockout.js:1609:40)
    at http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/Magento_Ui/js/lib/knockout/template/engine.js:197:28
    at mightThrow (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/jquery.js:3766:60)
    at process (http://localupgradephp8.project.com/static/version1669726130/frontend/Hiberus/project/en_US/jquery.js:3834:49) undefined

I use the datepicker binding in a “.html” file like so:

<div class="calendar-appointment" data-bind="datepicker: { storage: dateSelected, options: options}"></div>

dateSelected is an observable and options is an object.

If I edit or overwrite the core file vendor/magento/module-ui/view/base/web/js/lib/knockout/bindings/datepicker.js and comment the below code block it works perfect again, but I think is not the correct solution:

                bindingContext.$data.value.subscribe(function (newVal) {
                    if (!newVal) {
                        $(el).val('');
                    }
                }, this);

Any idea? Thank you