Hi dears I have going crazy to add a custom validation to vat field.
I tried several ways, but I don’t get an solve, I don’t know why?!
I have a module Vendor/module
i have create a custom rule validation with this method Custom Validation For Checkout Field
custom rule who named : validation works for vat id in register page.
When user wants to checkout available in source
so However i add below line in etc > di.xml :
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCustomerBlockWidgetName">
<plugin name="registerformvalidate" type="VendorModulePluginCustomerBlockWidgetName"/>
</type>
<type name="MagentoCustomerBlockWidgetTaxvat">
<plugin name="myvalidation" type="VendorModulePluginCustomerBlockWidgetTaxvat"/>
</type>
<type name="MagentoCheckoutBlockCheckoutLayoutProcessor">
<plugin name="vat_id" type="VendorModuleModelCheckoutLayoutProcessorPlugin" sortOrder="10"/>
</type>
</config>
in LayoutProcessorPlugin i have below code:
namespace VendorModuleModelCheckout;
class LayoutProcessorPlugin
{
public function afterProcess(
MagentoCheckoutBlockCheckoutLayoutProcessor $subject,
array $jsLayout
) {
$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
['shippingAddress']['children']['shipping-address-fieldset']['children']['vat_id'] = [
'component' => 'Magento_Ui/js/form/components/group',
'label' => __('vat number'),
'required' => true,
'sortOrder' => 200,
'type' => 'group',
'children' => [
[
'component' => 'Magento_Ui/js/form/element/abstract',
'config' => [
'customScope' => 'shippingAddress',
'template' => 'ui/form/field',
'elementTmpl' => 'ui/form/element/input'
],
'dataScope' => 'vat_id',
'provider' => 'checkoutProvider',
'validation' => ["min_text_length" => 10 , "max_text_length" => 10,'myvalidation' => true],
],
]
];
return $jsLayout;
}
}
As you see on above min_length or max_length or other default of magento 2 validation rules works well.
What’s my mistake for add custom validation for specific field ?