I have a unusual nested if statement where a third condition is needed to execute some code, but this condition is independent of my else clause. Thus, I've nested this condition inside the outer 2 conditions. The below works as it should, but I'm not positive this is the best way to handle a case like this. Should I use another method or refactor this in a way I'm not thinking of?
if ($('#preferred-contact').prop('selectedIndex') == index && !$(selector).val())
{
if (!$(label).parent().hasClass('has-error')) {
$(selector).after("<span class='help-block form-error'>Required Field</span>");
$(label).parent().addClass('has-error');
}
}
else {
$(selector + ' + .help-block').remove();
$(label).parent().removeClass('has-error');
}