Recently, I needed to override a specific function in a magento validator mixin.
The regular mixin didn’t work because my file gets called but then also the magento file gets called so magento original function is called after mine and I don’t want that. I want only my modified function to be called.
So I tried with a mixin of mixin:
'Magento_Module/js/path/to/file/validator-rules-mixin': {
'My_Module/js/path/to/element/validator-rules-mixin': true
},
This solution doesn’t work: my file is never called, only the original magento one is called.
My second attempt was to create a mixin that disables the original magento file and calls mine instead:
'Magento_Ui/js/lib/validation/validator': {
'Magento_Module/js/path/to/file/validator-rules-mixin': false,
'My_Module/js/path/to/file/validator-rules-mixin': true,
},
This works, of course, but it requires to copy the whole magento file into my file and edit only what I need to change. At this point, what’s the difference between this and mapping the two files in the requirejs-config file:
map: {
'*': {
'Magento_Module/js/path/to/file/validator-rules-mixin': 'My_Module/js/path/to/file/validator-rules-mixin'
}
}
In both cases, I have to copy the whole file, so what’s the difference between the two methods? Which one should be used?
As a related question: is it possible to override/replace an existing function in the validation file without copying the whole file?