0

I would like to understand how to add additional data to custom validation rule. I noticed in Magento 2 core files something like the following:

 validator.addRule(
 'validate-customer-company',
 function (value, params, data) {
 return !(data.customer && data['is_company_user']
 },
 $.mage.__('Message')
 ...

Does anyone know where data parameter comes from? In my case value comes from input field, params is true and data is undefined. And the validation is added to company_form.xml like this:

<field name="fieldName">
 ...
 <settings>
 <validation>
 <rule name="custom_rule" xsi:type="boolean">true</rule>
 </validation>
 </settings>

Thanks!

1 Answer 1

0

If you want to apply the Validation rules, there are two ways :

By using the UI component, you can use the Magento default rules. By using the Js, you can use Magento's default or create a new customization rule and then use it anywhere you want.

answered Feb 3, 2023 at 13:51

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.