关于magento2:Adding-custom-global-javascript-validation

88次阅读

共计 414 个字符,预计需要花费 2 分钟才能阅读完成。

Assuming you add a validation class via the frontend_class let’s say “validate-custom-class” you’ll need to use the following JS to add a custom validation based on a this class:

require([
    'jquery',
    'jquery/ui',
    'jquery/validate',
    'mage/translate'
], function($){ 
    $.validator.addMethod('validate-custom-class', function (value) { 
        // Add your validation logic here
        // Needs to return true if validation pass
        // Or false if validation fails
    }, $.mage.__('Field is not valid'));
});

正文完
 0