Skip to content

Commit

Permalink
Hide follow-up questions after clicking "None of the Above"
Browse files Browse the repository at this point in the history
* Extract the follow-up question hiding into its own method
* Call that method after clicking "None of the Above"

Co-authored-by: Tom Dooner <tdooner@codeforamerica.org>
  • Loading branch information
mquadri23 and tdooner committed Aug 22, 2023
1 parent 7d6d927 commit 57aae1c
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions app/assets/javascripts/honeycrisp.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,26 @@ var followUpQuestion = (function() {
});

// add click listeners to initial question inputs
$(self).find('.question-with-follow-up__question input').click(function(e) {
// reset follow ups
$(self).find('.question-with-follow-up__follow-up input').attr('disabled', true);
$(self).find('.question-with-follow-up__follow-up').hide();

$(self).find('.question-with-follow-up__question input').each(function(index, input) {
// if any of the inputs with a data-follow-up is checked then show the follow-up
if($(input).is(':checked') && $(input).attr('data-follow-up') != null) {
$(self).find('.question-with-follow-up__follow-up input').attr('disabled', false);
$($(this).attr('data-follow-up')).show();
}
});
})
$(self).find('.question-with-follow-up__question input').click(function(e) {fUQ.update($(self))})
});
},
update: function ($container){
// reset follow ups
$container.find('.question-with-follow-up__follow-up input').attr('disabled', true);
$container.find('.question-with-follow-up__follow-up').hide();

$container.find('.question-with-follow-up__question input').each(function(index, input) {
// if any of the inputs with a data-follow-up is checked then show the follow-up
if($(input).is(':checked') && $(input).attr('data-follow-up') != null) {
$container.find('.question-with-follow-up__follow-up input').attr('disabled', false);
$($(this).attr('data-follow-up')).show();
}
});
}
}
return {
init: fUQ.init
init: fUQ.init,
update: fUQ.update
}
})();

Expand Down Expand Up @@ -213,7 +215,15 @@ var noneOfTheAbove = (function() {
$noneCheckbox.click(function(e) {
$otherCheckboxes.prop('checked', false);
$otherCheckboxes.parent().removeClass('is-selected');

// If we just unchecked an <input> with a follow-up, let's reset the follow-up questions
// so it hides properly.
var $enclosingFollowUp = $noneCheckbox.closest('.question-with-follow-up');
if ($enclosingFollowUp) {
followUpQuestion.update($enclosingFollowUp);
}
});

}
};
return {
Expand Down

0 comments on commit 57aae1c

Please sign in to comment.