diff --git a/opentech/static_src/src/javascript/apply/batch-actions.js b/opentech/static_src/src/javascript/apply/batch-actions.js index f1ad28e3f4a60b05576d5a74bb2e78b04b4ff484..fe77d1f46c2d977cbb75160968a2c650a39262fa 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);