for our customer I've to create a custom validation for a field in the shipping-address-fieldset
. For that I've created a custom module in /app/code
. The js requirement works but the validation doesn't appear. Here is what I've got (anonymised):
/app/code/[Vendor]/[Module]/view/frontend/requirejs-config.js
var config = {
config: {
mixins: {
'mage/validation': {
'[Vendor]_[Module]/js/test-mixin': true
}
}
}
}
/app/code/[Vendor]/[Module]/view/frontend/web/js/test-mixin.js
define([
'jquery',
'jquery/ui',
'jquery/validate',
'mage/translate'
], function($) {
'use strict';
return function(){
$.validator.addMethod(
// validator name
'validate-five-words',
// validator check function
function(value, element){
return value.split(' ').length == 5;
},
// error message
$.mage.__('Please enter exactly five words')
);
};
});
and I've tried to add the validator to the company field in checkout_index_index.xml
<item name="company" xsi:type="array">
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">true</item>
<item name="validate-five-words" xsi:type="boolean">true</item>
</item>
</item>
The required-entry
validation and others like validate-street
are working correctly.
May be it's the wrong mixin hook or I miss something else.