2

Is there any way to extend validation/rules.js in custom module (not theme) with a new validation rule without overriding the original rules.js?

2

This is the best way to add a new rule without override the file rules.js and use on LayoutProcessor.php or jsLayout.

define(
    [
        'jquery',
        'Magento_Ui/js/lib/validation/validator'
    ],function ($,validator) {
    "use strict";
    return validator.addRule('validade-name-of-validation',
        function (value) {
            return /* your function */
        }, $.mage.__('Your error message.')
    );
});

Enjoy!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.