From 328a97847c0a0e24d617e3a3dfcfa220bc43ce3f Mon Sep 17 00:00:00 2001 From: Daniel Molares Date: Mon, 26 Aug 2024 15:00:01 -0400 Subject: [PATCH] Added safeguard for question bank validation --- src/creator.coffee | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/creator.coffee b/src/creator.coffee index 847be2d..0cdf72c 100755 --- a/src/creator.coffee +++ b/src/creator.coffee @@ -57,6 +57,10 @@ Hangman.factory 'Resource', ['$sanitize', ($sanitize) -> qsetItems.push item if item qset.items = [{items: qsetItems}] + # Ensure the question bank value is within bounds + if(qset.options.questionBankVal > items.length) + qset.options.questionBankVal = items.length + qset processQsetItem: (item) -> @@ -257,6 +261,10 @@ Hangman.controller 'HangmanCreatorCtrl', ['$timeout', '$scope', '$sanitize', 'Re $scope.removeItem = (index) -> $scope.items.splice index, 1 + # Update the question bank value when deletions occur so it is not out of bounds + if($scope.questionBankVal > $scope.items.length) + $scope.questionBankVal = $scope.questionBankValTemp = $scope.items.length + # If removing this item empties the page, paginate backwards pages = $scope.numberOfPages() if $scope.currentPage > pages - 1