Skip to content

Commit

Permalink
Fix: Do not run answer count validator on empty array #3069 (#3070)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Jul 8, 2021
1 parent 148125b commit a2059eb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ export class AnswerCountValidator extends SurveyValidator {
): ValidatorResult {
if (value == null || value.constructor != Array) return null;
var count = value.length;
if (count == 0) return null;
if (this.minCount && count < this.minCount) {
return new ValidatorResult(
null,
Expand Down
4 changes: 4 additions & 0 deletions tests/surveyquestiontests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,10 @@ QUnit.test("Validators for other values - checkbox, Bug #722", function(
true,
"There should be at least 2 values selected"
);
question.value = [];
assert.equal(question.hasErrors(), false, "We do not check the empty array");
question.value = undefined;
assert.equal(question.hasErrors(), false, "We do not check the empty value");
});
QUnit.test(
"other values in choices, hasOther=false, Bug(Editor) #242",
Expand Down

0 comments on commit a2059eb

Please sign in to comment.