cancel
Showing results for 
Search instead for 
Did you mean: 

Overwriting rules.js in module

SOLVED

Overwriting rules.js in module

I want to overwrite rules.js in my module.

 

Original location: vendor/module-ui/view/base/web/js/lib/validation/rules.js

 

I created vendor/module/view/base/requirejs-config.js

 

var config = {
    'map': {
        '*': {
            'ui/js/lib/validation/rules': 'BB_Checkout/js/lib/validation/rules'
        }
    }

I don't get an error but it also doesn't apply the validation rules. If i move the file to my theme it does work so the rules.js file is correct.

 

My rules.js file is in Vendor/Module/view/base/web/js/lib/validation.

 

I also added the validation rules to the checkout_index_index.xml

 

Any idea? I feel like the path may be wrong since the path's in module-ui seem to be a bit different then the rest because it also has it's own requirejs-config in vendor.

 

Also my checkout_index_index.xml is in Vendor/Module/view/frontend/layout/ so it's in frontend but the rules.js is in base, maybe that is part of the problem?

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Overwriting rules.js in module

I ended up going with Damian's solution in a different topic:

 

https://community.magento.com/t5/Magento-2-x-Programming/Add-custom-validator-on-phonenumber-in-chec...

 

My main problem was that i indeed needed to use 'Magento_Ui' in the requirejs and also needed to copy utils.js.

View solution in original post

3 REPLIES 3

Re: Overwriting rules.js in module

Please keep below code in your requirejs-config.js file,

var config = {
    'map': {
        '*': {
            'Magento_Ui/js/lib/validation/rules': 'BB_Checkout/js/lib/validation/rules'
        }
    }

Just clear cache and check.

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: Overwriting rules.js in module

I figured out that overwriting rules.js might not be the best way to add a custom validator. So i'm trying this now:  https://community.magento.com/t5/Magento-2-x-Programming/Add-custom-validator-on-phonenumber-in-che...

 

Sadly I can find no way to close this topic.

Re: Overwriting rules.js in module

I ended up going with Damian's solution in a different topic:

 

https://community.magento.com/t5/Magento-2-x-Programming/Add-custom-validator-on-phonenumber-in-chec...

 

My main problem was that i indeed needed to use 'Magento_Ui' in the requirejs and also needed to copy utils.js.