Skip to content

Commit

Permalink
No Validation Error appears if the Minimum Selected Choices (minSelec…
Browse files Browse the repository at this point in the history
…tedChoices) property value is greater than Maximum Selected Choices (maxSelectedChoices) fix #7601 (#7602)
  • Loading branch information
andrewtelnov authored Dec 29, 2023
1 parent c481611 commit 36ccab8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/question_checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,20 @@ Serializer.addClass(
[
{ name: "showSelectAllItem:boolean", alternativeName: "hasSelectAll" },
{ name: "separateSpecialChoices", visible: true },
{ name: "maxSelectedChoices:number", default: 0 },
{ name: "minSelectedChoices:number", default: 0 },
{ name: "maxSelectedChoices:number", default: 0,
onSettingValue: (obj: any, val: any): any => {
if(val <= 0) return 0;
const min = obj.minSelectedChoices;
return min > 0 && val < min ? min : val;
}
},
{ name: "minSelectedChoices:number", default: 0,
onSettingValue: (obj: any, val: any): any => {
if(val <= 0) return 0;
const max = obj.maxSelectedChoices;
return max > 0 && val > max ? max : val;
}
},
{
name: "selectAllText",
serializationProperty: "locSelectAllText",
Expand Down
25 changes: 24 additions & 1 deletion tests/question_baseselecttests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1608,4 +1608,27 @@ QUnit.test("isUsingRestful & loading", function(assert) {
assert.equal(q1.isUsingRestful, false, "q1 #2");
q1.choicesByUrl.url = "edf";
assert.equal(q1.isUsingRestful, true, "q1 #3");
});
});
QUnit.test("checkbox max(min)SelectedChoices validation", (assert) => {
const survey = new SurveyModel({
elements: [
{
type: "checkbox",
name: "q1"
}
]
});
const q = <QuestionCheckboxModel>survey.getQuestionByName("q1");
q.minSelectedChoices = 10;
assert.equal(q.minSelectedChoices, 10, "q.minSelectedChoices, #1");
q.maxSelectedChoices = 5;
assert.equal(q.maxSelectedChoices, 10, "q.maxSelectedChoices, #2");
q.minSelectedChoices = 20;
assert.equal(q.minSelectedChoices, 10, "q.minSelectedChoices, #3");
q.maxSelectedChoices = 0;
q.minSelectedChoices = 20;
assert.equal(q.minSelectedChoices, 20, "q.minSelectedChoices, #4");
q.minSelectedChoices = 0;
q.maxSelectedChoices = 5;
assert.equal(q.maxSelectedChoices, 5, "q.maxSelectedChoices, #5");
});

0 comments on commit 36ccab8

Please sign in to comment.