JSFiddle - React, Tailwind, and code Playground
HTML
<div>
<label>Question #1</label>
<span class="options">
No <input type="radio" class="toggle_group required" value="0" id="restrictions_no" name="restrictions">
Yes <input type="radio" class="toggle_group required" value="1" id="restrictions_yes" name="restrictions" checked="checked">
</span>
</div>
<div class="details_group">
<div>
<label>Follow Up #1</label>
<span>
No <input type="radio" class="toggle" value="0" id="followup_1_no" name="followup_1" checked="checked">
Yes <input type="radio" class="toggle" value="1" id="followup_1_yes" name="followup_1">
</span>
<span class="details">
<textarea maxlength="1000" id="followup_1_details"></textarea>
</span>
</div>
<div>
<label>Follow Up #2</label>
<span>
No <input type="radio" class="toggle" value="0" id="followup_2_no" name="followup_2">
Yes <input type="radio" class="toggle" value="1" id="followup_2_yes" name="followup_2" checked="checked">
</span>
<span class="details">
<textarea maxlength="1000" id="followup_2_details"></textarea>
</span>
</div>
</div>
JavaScript
$('.toggle').on('change', function() {
var showOrHide = false;
$(this).siblings('input[type=radio]').andSelf().each(function() {
if ($(this).val() == 1 && $(this).prop("checked")) showOrHide = true;
})
$(this).parent().next('.details').toggle(showOrHide);
$(this).parent().next('.details').find('textarea').addClass('required');
if (showOrHide == false) {
$(this).parent().next('.details').find('textarea').val('');
$(this).parent().next('.details').find('textarea').removeClass('required');
}
}).change()
$('.toggle_group').on('change', function() {
var showOrHide = false;
$(this).siblings('input[type=radio]').andSelf().each(function() {
if ($(this).val() == 1 && $(this).prop("checked")) showOrHide = true;
})
$(this).parent().parent().next('.details_group').toggle(showOrHide)
$(this).parent().parent().next('.details_group').find('input:radio').addClass('required');
$(this).parent().parent().next('.details_group').find('textarea').addClass('required');
if (showOrHide == false) {
$(this).parent().parent().next('.details_group').find('input:radio').removeAttr('checked')
$(this).parent().parent().next('.details_group').find('input:radio').removeClass('required');
$(this).parent().parent().next('.details_group').find('textarea').val('');
$(this).parent().parent().next('.details_group').find('textarea').removeClass('required');
}
}).change()