How I can build difficult forms in yii2?

I have got form with options, that will change after user actions. For one select option will be one fields, for second - second fields. I have got a lot of some fields in one form.

I built model with all fields and validation rules.

I create view with custom.js, where with jquery I change fields, like I want to see (show, hide options).

All is ok and validation is good.

But I have got only one problem.

When I submit the form, fields in hidden divs gives error for not validation fields (blank or something else).

And nothing will be sending to backend working. How I can kill validation of hidden form fields (which with display:none options)?

I want to see validation for them only if they are visible. Is it possible?

I solve it with own jquery code and this "callback" object:




$('#reg-form').on('beforeValidate', function () {});



but I still will be interesting to read some good "how to" article for best solution about it.