From 4c5f275ac0d900a79f05ba0d18b152994d47dbca Mon Sep 17 00:00:00 2001 From: Sree P Date: Tue, 5 Mar 2024 15:17:37 -0800 Subject: [PATCH 1/2] Fix for when there are mutiple checkbox sets on one page - the "none of the above" toggle will be applied only to its own set --- app/assets/javascripts/honeycrisp.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/honeycrisp.js b/app/assets/javascripts/honeycrisp.js index 7a7057e..2a965f6 100644 --- a/app/assets/javascripts/honeycrisp.js +++ b/app/assets/javascripts/honeycrisp.js @@ -212,23 +212,27 @@ var inputGroupSelector = (function() { var noneOfTheAbove = (function() { var noneOf = { init: function () { - var $noneCheckbox = $('#none__checkbox'); - var $otherCheckboxes = $('input[type=checkbox]').not('#none__checkbox'); + const $noneCheckboxes = $('input[id^=none__checkbox]'); + const $otherCheckboxes = $('input[type=checkbox]').not('[id^=none__checkbox]'); // Uncheck None if another checkbox is checked - $otherCheckboxes.click(function(e) { + $otherCheckboxes.click(function (e) { + const $name = this.name + const $noneCheckbox = $('#none__checkbox-' + $name.substring(0, $name.length - 2)); $noneCheckbox.prop('checked', false); $noneCheckbox.parent().removeClass('is-selected'); }); // Uncheck all others if None is checked - $noneCheckbox.click(function(e) { - $otherCheckboxes.prop('checked', false); - $otherCheckboxes.parent().removeClass('is-selected'); + $noneCheckboxes.click(function (e) { + const $id = $(this).attr('id') + const $noneSiblingCheckboxes = $('input[id^=' + $id.substring(15)); + $noneSiblingCheckboxes.prop('checked', false); + $noneSiblingCheckboxes.parent().removeClass('is-selected'); // If we just unchecked an with a follow-up, let's reset the follow-up questions // so it hides properly. - var $enclosingFollowUp = $noneCheckbox.closest('.question-with-follow-up'); + var $enclosingFollowUp = $noneCheckboxes.closest('.question-with-follow-up'); if ($enclosingFollowUp) { followUpQuestion.update($enclosingFollowUp); } From 42809ebc654e463e84cdd57e43bb797770f28852 Mon Sep 17 00:00:00 2001 From: Sree P Date: Tue, 5 Mar 2024 16:17:54 -0800 Subject: [PATCH 2/2] fixes --- app/assets/javascripts/honeycrisp.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/honeycrisp.js b/app/assets/javascripts/honeycrisp.js index 2a965f6..2e436c7 100644 --- a/app/assets/javascripts/honeycrisp.js +++ b/app/assets/javascripts/honeycrisp.js @@ -212,27 +212,27 @@ var inputGroupSelector = (function() { var noneOfTheAbove = (function() { var noneOf = { init: function () { - const $noneCheckboxes = $('input[id^=none__checkbox]'); - const $otherCheckboxes = $('input[type=checkbox]').not('[id^=none__checkbox]'); + var $noneCheckboxes = $('input[id^=none__checkbox]'); + var $otherCheckboxes = $('input[type=checkbox]').not('[id^=none__checkbox]'); // Uncheck None if another checkbox is checked $otherCheckboxes.click(function (e) { - const $name = this.name - const $noneCheckbox = $('#none__checkbox-' + $name.substring(0, $name.length - 2)); + var $name = this.name + var $noneCheckbox = $('#none__checkbox-' + $name.substring(0, $name.length - 2)); $noneCheckbox.prop('checked', false); $noneCheckbox.parent().removeClass('is-selected'); }); // Uncheck all others if None is checked $noneCheckboxes.click(function (e) { - const $id = $(this).attr('id') - const $noneSiblingCheckboxes = $('input[id^=' + $id.substring(15)); + var $id = $(this).attr('id') + var $noneSiblingCheckboxes = $('input[id^=' + $id.substring(15)); $noneSiblingCheckboxes.prop('checked', false); $noneSiblingCheckboxes.parent().removeClass('is-selected'); // If we just unchecked an with a follow-up, let's reset the follow-up questions // so it hides properly. - var $enclosingFollowUp = $noneCheckboxes.closest('.question-with-follow-up'); + var $enclosingFollowUp = $(this).closest('.question-with-follow-up'); if ($enclosingFollowUp) { followUpQuestion.update($enclosingFollowUp); }