I did it works at this way, but I don't know if it is the right magento way to do... but works.
In my custom shipping module, I've this shipping-rates-validation-rule.js
:
define(
[],
function () {
'use strict';
return {
getRules: function () {
return {
'postcode': {
'required': true,
// here I set a new validation rule
'validate_zip_br': true
}
};
}
};
}
);
And my shipping-rates-validator.js
:
define(
[
'jquery',
'mageUtils',
'Vendor_Module/js/model/shipping-rates-validation-rules',
'mage/translate'
],
function ($, utils, validationRules, $t) {
'use strict';
return {
validationErrors: [],
validate: function (address) {
var self = this;
this.validationErrors = [];
$.each(validationRules.getRules(), function (field, rule) {
if (rule.required && utils.isEmpty(address[field])) {
var message = $t('Field ') + field + $t(' is required.');
self.validationErrors.push(message);
/*### AND HERE ###*/
// here I directly trate the rule setted before
} else if (rule.validate_zip_br) {
var zip = address[field];
zip = zip.replace(/-|_/g,'');
if(zip.length != 8) {
var message = $t('Field ') + field + $t(' has min-length of 8.');
self.validationErrors.push(message);
}
}
});
return !Boolean(this.validationErrors.length);
}
};
}
);
So, as you can see, I've directly coded the validation on my validator file, I've tried to use mix-ins to create a new validation rule, but it does not work, however with the above code I've reached my expected behavior..