Disabling required for form field inside div with display none

I have a form where the form elements are grouped in several divs.
Depending on user choices certain divs will display and others will have display:none.

I want some fields to be required but only when the surrounding div has the value display: block.

Is there a way to do this?