Skip to content

Commit

Permalink
Checkboxes/TagBox with Select All and None - Survey results contains …
Browse files Browse the repository at this point in the history
…an unexpected blank/empty string fix #7657 (#7664)
  • Loading branch information
andrewtelnov authored Jan 15, 2024
1 parent 7ff111e commit d4b3703
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/question_checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,11 @@ export class QuestionCheckboxModel extends QuestionCheckboxBase {
var res = [];
var visItems = this.visibleChoices;
for (var i = 0; i < visItems.length; i++) {
const item = visItems[i];
if(item === this.selectAllItem) continue;
var val = visItems[i].value;
if (Helpers.isTwoValueEquals(val, this.invisibleOldValues[val])) {
if (!this.isItemSelected(visItems[i])) {
if (!this.isItemSelected(item)) {
res.push(val);
}
delete this.invisibleOldValues[val];
Expand Down
26 changes: 26 additions & 0 deletions tests/question_baseselecttests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1632,3 +1632,29 @@ QUnit.test("checkbox max(min)SelectedChoices validation", (assert) => {
q.maxSelectedChoices = 5;
assert.equal(q.maxSelectedChoices, 5, "q.maxSelectedChoices, #5");
});
QUnit.test("checkbox, selectAll & survey.data, bug#7657", (assert) => {
const survey = new SurveyModel({
"elements": [
{
"type": "checkbox",
"name": "q1",
"isRequired": true,
"choices": [
"One",
"Two",
"Three"
],
"showNoneItem": true,
"showSelectAllItem": true
}
]
});
const q = <QuestionCheckboxModel>survey.getQuestionByName("q1");
q.selectAll();
q.clickItemHandler(q.choices[2]);
assert.deepEqual(q.value, ["One", "Two"], "q.value, #1");
assert.deepEqual(survey.data, { q1: ["One", "Two"] }, "survey.data, #1");
survey.doComplete();
assert.deepEqual(q.value, ["One", "Two"], "q.value, #2");
assert.deepEqual(survey.data, { q1: ["One", "Two"] }, "survey.data, #2");
});

0 comments on commit d4b3703

Please sign in to comment.