Validation on collapsing forms while submit

I have 5 collapsing forms in my User submission page. These 5 collapsing forms expand based on a checkbox selection.
I have set the Required property as True in the editor and checking the .valid inside onBeforeSave(). This works perfect when all 5 forms expands. On case when user selection expands less than 5 forms, while submission it doesn’t work because the collapsed form has fields that is set as Required in editor.
Any help how to solve this? Is there a way to set the Editor Required field on and off via code? That will solve but I don’t know what is that code.
Or is there any other way?

Hi,

You can set the required state using code
See here
http://www.wix.com/code/reference/$w.TextInput.html#required