Make field required if checkbox checked

How does GF build the logic to determine if a field is required or not? I am trying to create it so when a checkbox option is checked other fields within the form become required. I created some javascript which adds a required attribute, but my form still submits.


$(document).ready(function() {
	$('#choice_3_7_2').on("change", function() {
		if (($(this).prop('checked'))) {
				$("#field_3_8").attr('required', ($(this).attr('required') == "required" ? "" : "required"));
			}
	});
});

Any help would be appreciated. Thanks!

Hi Mareider. Take a look at this example which uses the gform_pre_validation filter: