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.

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

1 Answer 1

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

3
  • 1
    Please update complete implementation. So I could try that Apr 12, 2019 at 7:39
  • 1
    I've removed the return function then it worked but what does the difference here.. Apr 12, 2019 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, 2019 at 10:20

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.