how to change magento 2 date.js form file
-
24-02-2021 - |
Question
I want to change :
magento/module-ui/view/base/web/js/form/element/date.js file
and set my custom date file , for this purpose I've added this line to my requirejs-config in my module :
'map': {
'*': {
'Magento_Ui/js/form/element/date' : 'MyNamespace_MyModule/js/date_form'
}
},
but when I refresh page I get this error in console :
Uncaught TypeError: elem.initContainer is not a function at UiClass.initElement (collection.js:57)
and magento can't load date input element .
I think the problem is this part at date.js :
elementTmpl: 'ui/form/element/date',
it seems magento can't find this path for load it's html template .
I changed template path to this :
elementTmpl: 'Magento_Ui/form/element/date',
but noting changed .
how can I change this path base on my module ?
note : I don't want change date.html template file and I want to use magento default template file .
Solution
It is better to put your custom date.js
on the same path level of core date.js
like this
'map': {
'*': {
'Magento_Ui/js/form/element/date' : 'MyNamespace_MyModule/js/form/element/date'
}
},