From 07d9c12e9ddbb87b4bb1d0d6917a57f68cff7b5d Mon Sep 17 00:00:00 2001 From: Chris Lawton <chris.lawton@torchbox.com> Date: Tue, 22 Jan 2019 16:22:59 +0000 Subject: [PATCH] reset the check all input if all were selected and then one was unselected --- .../src/javascript/apply/batch-actions.js | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/opentech/static_src/src/javascript/apply/batch-actions.js b/opentech/static_src/src/javascript/apply/batch-actions.js index f1ad28e3f..fe77d1f46 100644 --- a/opentech/static_src/src/javascript/apply/batch-actions.js +++ b/opentech/static_src/src/javascript/apply/batch-actions.js @@ -7,30 +7,36 @@ const $allCheckboxInput = $('.js-batch-select-all'); const activeClass = 'batch-actions-enabled'; - $allCheckboxInput.change(function() { + $allCheckboxInput.change(function () { if ($(this).is(':checked')) { - $checkbox.each(function() { + $checkbox.each(function () { this.checked = true; }); - } else { - $checkbox.each(function() { + } + else { + $checkbox.each(function () { this.checked = false; }); } updateCount(); - }) + }); $checkbox.change(function () { // see how many checkboxes are :checked - checkTotalSelected(); + toggleBatchActions(); // updates selected checbox count updateCount(); + + // reset the check all input + if (!$(this).is(':checked') && $allCheckboxInput.is(':checked')) { + resetCheckAllInput(); + } }); - function checkTotalSelected() { + function toggleBatchActions() { if ($('.js-batch-select:checked').length) { $body.addClass(activeClass); } @@ -43,6 +49,10 @@ $('.js-total-actions').html($('.js-batch-select:checked').length); } + function resetCheckAllInput() { + $allCheckboxInput.prop('checked', false); + } + })(jQuery); -- GitLab