Skip to content

Commit

Permalink
Merge pull request #7952 from surveyjs/bug/A403-other-and-comment-dis…
Browse files Browse the repository at this point in the history
…play-value

Fixed surveyjs/survey-analytics#403 - Tabulator and Checkboxes - The Comment box value replaces the Other option value
  • Loading branch information
andrewtelnov authored Mar 13, 2024
2 parents 87fb5eb + f6185fa commit 20149d8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/question_baseselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1131,15 +1131,15 @@ export class QuestionSelectBase extends Question {
protected getDisplayArrayValue(keysAsText: boolean, value: any,
onGetValueCallback?: (index: number) => any): string {
var items = this.visibleChoices;
var strs = [];
const vals = [];
var strs = [] as Array<string>;
const vals = [] as Array<any>;
for (var i = 0; i < value.length; i++) {
vals.push(!onGetValueCallback ? value[i] : onGetValueCallback(i));
}
if(Helpers.isTwoValueEquals(this.value, vals)) {
this.getMultipleSelectedItems().forEach(item => strs.push(this.getItemDisplayValue(item)));
if (Helpers.isTwoValueEquals(this.value, vals)) {
this.getMultipleSelectedItems().forEach((item, index) => strs.push(this.getItemDisplayValue(item, vals[index])));
}
if(strs.length === 0) {
if (strs.length === 0) {
for (var i = 0; i < vals.length; i++) {
let valStr = this.getChoicesDisplayValue(items, vals[i]);
if (valStr) {
Expand All @@ -1149,8 +1149,15 @@ export class QuestionSelectBase extends Question {
}
return strs.join(", ");
}
private getItemDisplayValue(item: ItemValue): string {
if(item === this.otherItem && this.comment) return this.comment;
private getItemDisplayValue(item: ItemValue, val?: any): string {
if (item === this.otherItem) {
if (this.hasOther && this.showCommentArea && !!val) {
return val;
}
if (this.comment) {
return this.comment;
}
}
return item.locText.textOrHtml;
}
private getFilteredChoices(): Array<ItemValue> {
Expand Down
17 changes: 17 additions & 0 deletions tests/question_baseselecttests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1814,3 +1814,20 @@ QUnit.test("Do not show show choices in designer", function(assert) {
assert.equal(question.visibleChoices.length, 5 + 1 + 3, "Show choices in designer, #1");
settings.supportCreatorV2 = false;
});
QUnit.test("question checkbox displayValue() with other and comment", (assert) => {
const q1 = new QuestionCheckboxModel("q1");
q1.fromJSON({
"type": "checkbox",
"name": "q1",
"showCommentArea": true,
"commentText": "Comment",
"choices": [
"Item 1",
"Item 2",
"Item 3"
],
"showOtherItem": true
});
q1.value = ["Item 1", "Item 2", "Other Value"];
assert.deepEqual(q1.displayValue, "Item 1, Item 2, Other Value", "Other value should be kept");
});

0 comments on commit 20149d8

Please sign in to comment.