Basically I am trying to add custom validation rule in existing street field of shipping address form Checkout in magento 2 where pobox should not be allowed. I tried using mixin with requirejs-config.js which works well as it gets called till (console.log(hello)) but I am not sure why my ‘validate-street-part‘ is not getting called from layoutprocessor and adding ‘validate-street-part‘ to (mage/validation.js). Any advise or suggestion would be appreciated.
appdesignfrontendVendorMagento_Checkoutwebjspobox-mixin.js
define([
'jquery',
'jquery/ui',
'jquery/validate',
'mage/translate'
], function ($) {
"use strict";
return function () {
console.log("hello");
$.validator.addMethod(
'validate-street-part',
function (v) {
var pattern = /^([post]*)$/.test(v);
console.log(pattern);
if(!pattern){
console.log("return true");
return true;
}else{
console.log("return false");
return false;
}
},
$.mage.__("Please note that we cannot ship to PO Boxes. Please enter a physical address.")
);
};
});
appdesignfrontendVendorMagento_Checkoutrequirejs-config.js
var config = {
config: {
mixins: {
'mage/validation': {
'Magento_Checkout/js/pobox-mixin' : true
}
}
}
};
appcodeVendorCheckoutetcdi.xml
< ?xml version="1.0"?>
appcodeVendorCheckoutBlockCheckoutLayoutProcessor.php
< ?php
namespace VendorCheckoutBlockCheckout;
class LayoutProcessor
{
public function afterProcess(
MagentoCheckoutBlockCheckoutLayoutProcessor $subject,
array $jsLayout
) {
$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
['shippingAddress']['children']['shipping-address-fieldset']['children']['street']['validation']['validate-street-part'] = 1;
return $jsLayout;
}
}