是否可以覆盖Magento_Ui / js / lib / validation / rules.js文件而无需映射文件,如下例所示?
a | b
100 | Rock+Y;Paper+No;Scissor+Yes;Dragon+Y;<br>
101 | Rock+N;Paper+No;Scissor+Yes;Dragon+N;<br>
102 | Rock+Y;Paper+Yes;Scissor+N;Dragon+Y;
是否有更优雅的方式来添加可在结帐步骤中使用的表单验证?
由于
答案 0 :(得分:0)
在 Vendor/Module/view/adminhtml/ 中创建 requirejs-config.js
var config = {
config: {
mixins: {
'Magento_Ui/js/lib/validation/rules': {
'Vendor_Module/js/lib/validation/rules': true
}
}
}
};
在 Vendor/Module/view/base/web/js/lib/validation 中创建 rules.js
define([
'jquery',
'underscore',
'moment',
'mage/translate'
], function ($, _, moment) {
'use strict';
return function (validator) {
var validators = {
'validate-number-custom': [
function (value) {
console.log("You logic here");
return /^[a-zA-Z ]*$/i.test(value);
},
$.mage.__('Please enter a valid number in this field.')
]
};
validators = _.mapObject(validators, function (data) {
return {
handler: data[0],
message: data[1]
};
});
return $.extend(validator, validators);
};
});