1

I have a mixin which is extending functionality for validation purpose. See the code below

define([
'jquery',
'Magento_Ui/js/lib/validation/validator'
], function ($, validatorlib) {
"use strict";
console.log('test');
return function () {
    console.log('test123');  // this is coming in console
    var regex_pattern = window.address_field_pattern;

    if (regex_pattern == '')
        return true;

    validatorlib.addRule(
        'validate-gearalphanumeric',
        function (value) {
            if (value)
                return regex_pattern.test(value);
            else
                return true;

        },
        $.mage.__('Please use only numbers and Latin characters in this field.')
    );

    $.validator.addMethod(
        'validate-gearalphanumeric',
        function (value) {
            if (value)
                return regex_pattern.test(value);
            else
                return true;

        },
        $.mage.__('Please use only numbers and Latin characters in this field.')
    );
}
});

NOTE : It was working in 2.2 version

and I do have verified the implementation as well but it seems not working.

Anyone find any issue in above do let me know.

  • did you get any error Prathap? – fmsthird Apr 12 '19 at 7:33
  • No error just it is not coming inside the function which I've given in comment. See code – Prathap Gunasekaran Apr 12 '19 at 7:33
0

I am adding validation like this and works for me:

define([
        'jquery',
        'jquery/ui',
        'jquery/validate',
        'mage/translate'
    ], function($){
        'use strict';
        $.validator.addMethod(
            "ruleValidationName",
            function(value, element) {
                return false;
            },
            $.mage.__("Your validation message")
        );
    });

so no return function() is needed

  • 1
    Please update complete implementation. So I could try that – Prathap Gunasekaran Apr 12 '19 at 7:39
  • 1
    I've removed the return function then it worked but what does the difference here.. – Prathap Gunasekaran Apr 12 '19 at 8:48
  • you are not returning a function since you don;t need to make a mixin for validations, you can just add them in a custom script, that is why you dont need that part – Vlad Patru Apr 12 '19 at 10:20

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.