1

I am trying to add a custom validation rule with a mixin to use at the checkout.
I am following this tutorial.

So I have:

Mageplaza/HelloWorld/view/frontend/requirejs-config.js

var config = {
    config: {
        mixins: {
            'Magento_Ui/js/lib/validation/validator': {
                'Mageplaza_HelloWorld/js/validator-mixin': true
            }
        }
    }
};

Mageplaza/HelloWorld/view/frontend/js/validator-mixin.js

define([
    'jquery',
    'moment'
], function ($, moment) {
    'use strict';

    return function (validator) {

        validator.addRule(
            'validate-minimum-age',
            function (value, params, additionalParams) {
                return $.mage.isEmptyNoTrim(value) || moment(value, additionalParams.dateFormat).isBefore(moment().subtract(params.minimum_age, 'y'));
            },
            $.mage.__("Sorry, you don't have the age to purchase the current articles.")
        );

        return validator;
    };
});

I never call this validation just yet, but when I go to the checkout, I get this message:

Uncaught Error: Script error for: Mageplaza_HelloWorld/js/validator-mixin
2

Location of


Mageplaza/HelloWorld/view/frontend/js/validator-mixin.js

should be


Mageplaza/HelloWorld/view/frontend/web/js/validator-mixin.js

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.