Skip to content

Commit

Permalink
Merge pull request #79 from dmols/issue/78-questionBank-validation-bu…
Browse files Browse the repository at this point in the history
…gfix

Added question bank value safeguarding
  • Loading branch information
clpetersonucf authored Sep 17, 2024
2 parents a0e5a2a + 0caf896 commit 4897258
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/controllers/ctl-creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,14 @@ export const ControllerThisOrThatCreator = function($scope, $timeout, $sanitize,
$scope.questionBankVal
)
if (qset) {
// Ensure the question bank value isn't out of bounds when the widget is saved
if($scope.questionBankVal > $scope.questions.length) {
$scope.questionBankVal = $scope.questions.length
}

return Materia.CreatorCore.save($sanitize($scope.title), qset, 2)
}

} else {
Materia.CreatorCore.cancelSave('Please make sure every question is complete')

Expand Down Expand Up @@ -297,6 +303,11 @@ export const ControllerThisOrThatCreator = function($scope, $timeout, $sanitize,
$timeout(_noTransition, 660, true)
$scope.questions.splice(index, 1)

// Make sure questionBank value is within bounds after removing a question
if($scope.questionBankVal > $scope.questions.length) {
$scope.questionBankVal = $scope.questionBankValTemp = $scope.questions.length
}

if ($scope.currIndex === $scope.questions.length) {
$timeout(() => _updateIndex('remove'), 200, true)
}
Expand Down

0 comments on commit 4897258

Please sign in to comment.