I followed this guide in order to add a new validation to my checkout. I deployed the content, cleared the cache and enabled the module several times but the validation is not working.

I also added a console.log('foobar'); to the isGmail.js file inside the validate function, but it never gets printed. I also checked the pub folder for the content and it is right there.

Magento 2.2.3

Any ideas what might be wrong?


1 Answer 1


not sure exactly what's going on. I followed the tutorial as well and was able to get everything to show up.

The first thing to check is that the files are being loaded in checkout. Jump into your inspector and under the network tab make sure both file are being loaded.

enter image description here

If they are, then you know that your deploy is correct and that the XML that you have is correct as well. If the files aren't showing up, then check your XML first to make sure that you have that correct. The file i have is full of other checkout stuff when i tested it, but the section that i grabbed is working for me, so odds are that's fine.

If the view file is loading and not the model file then it might be an issue with the call to that file in the JS dependencies. Make sure Mageplaza_HelloWorld/js/model/isGmail is the correct path you have for your module.

From there you can check with some test code. For me, this console.log loads then i hit checkout:

    function (Component, additionalValidators, gmailValidation) {
        'use strict';
        console.log('in the view/gmail');
        return Component.extend({});

And for this section, the first console.log loads when i hit the checkout page and the second only triggers when i hit the place order button:

    function ($) {
        'use strict';
        console.log('outside return in the model/gmail');
        return {
             * Validate checkout agreements
             * @returns {Boolean}
            validate: function () {
                var emailValidationResult = false;
                var email = $('form[data-role=email-with-possible-login]').val();
                if(~email.search("gmail.com")){ //should use Regular expression in real store.
                    emailValidationResult = true;
                console.log('inside validate in the model/gmail');
                return emailValidationResult;

enter image description here

Play around with it and let me know where you are getting stuck.

As a side note, this user experience is really bad, as in you can't place the order, but there is no feedback on what is wrong and why it's not working. I would check this out and see if that gets you closer to where you want to be for custom form validation. It's not the same application, but it's using the same concepts.


  • Have you found solution sir? If yes, Please share it here and help! Jun 1, 2021 at 9:02
  • the original post worked for me. what issue are you running into?
    – circlesix
    Jun 14, 2021 at 22:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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