0

I have to add three validation rule and as you see below code works well for one rule : validation-mixin.js

define([
    'jquery'
], function ($) {
    "use strict";
    console.log('this is own');
    return function (validator) {
        $.validator.addMethod(
            'myvalidation',
            function (value) {
                // Some custom validation stuff here
                
                return false;
            },
            $.mage.__('myvalidation')
        );
        return validator;
    }
});

I searched the site questions and does not find a question something like this.

Is any way to add more validation rules in magento2 with out override rules.Js file ?

1 Answer 1

1

Just use more times addMethod and add more rules in the same mixin.

define([
    'jquery'
], function ($) {
    "use strict";
    
    return function (validator) {

        $.validator.addMethod(
            'firstvalidation',
            function (value) {
                // Some custom validation stuff here

                return false;
            },
            $.mage.__('myvalidation')
        );

        $.validator.addMethod(
            'secondvalidation',
            function (value) {
                // Some custom validation stuff here

                return false;
            },
            $.mage.__('Second validation')
        );

        $.validator.addMethod(
            'nextvalidation',
            function (value) {
                // Some custom validation stuff here

                return false;
            },
            $.mage.__('Hey, I am next :)')
        );

        return validator;
    }
});
1
  • 1
    Thank You Works with charm!! Like Benz ;)
    – Peren
    Sep 22, 2022 at 20:57

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.