3

Validate Ui Component generated form fields inside dynamic rows container that are dependent of another field value

There is a possibility to add one or more addresses for a new/existing customer via Magento 2 backend|admin side.

There is a functionality called dynamic rows.

Basically every time you want to add a new address you click a button and a new form is generated.

This forms are generated via Ui Component with the help of knockout js. Id's on this input form fields are random. And here comes the problem. Let's say we want to validate the VAT number based of the value entered for the country.

I know how to add validation on the VAT number field but how do I retrieve information about the country?

Inside the validation function we only have access to the value entered. No information about the field id or name and given that there are more possible forms how do I know how which country field do I need to retrieve selected country information from?

I have found a pattern in the names of the field and I have a solution in which I basically check all forms one by one. This is really dirty and checks values already checked which makes it highly inefficient.

Can't I pass information about the html node to the validation function? Is there a elegant way to solve this?

Any help is appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.