Skip to content

Commit

Permalink
Merge pull request #8880 from surveyjs/bug/8879-Comment-displays-unde…
Browse files Browse the repository at this point in the history
…fined-when-resetting-value

A Comment displays undefined when resetting the value
  • Loading branch information
OlgaLarina authored Oct 1, 2024
2 parents 834f00c + 485a7d7 commit d44bd03
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/survey-core/src/utils/text-area.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class TextAreaModel {

public getTextValue(): string {
if (!!this.options.getTextValue)
return this.options.getTextValue();
return this.options.getTextValue() || "";
return "";
}
public onTextAreaChange(event: any): void {
Expand Down
1 change: 1 addition & 0 deletions packages/survey-core/tests/entries/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export * from "../question_signaturepadtests";
export * from "../question_matrix_base_tests";
export * from "../question_matrix_tests";
export * from "../question_tagbox_tests";
export * from "../question_comment_tests";
export * from "../cssClassBuilderTests";
export * from "../listModelTests";
export * from "../dropdown_list_model_test";
Expand Down
66 changes: 66 additions & 0 deletions packages/survey-core/tests/question_comment_tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { SurveyModel } from "../src/survey";
import { QuestionCommentModel } from "../src/question_comment";

export default QUnit.module("Comment question");

QUnit.test("A Comment displays undefined when resetting the value", function (assert) {
let json = {
"elements": [
{
"type": "comment",
"name": "billing-address",
"title": "Billing address",
"rows": 2
},
{
"type": "boolean",
"name": "shipping-same-as-billing",
"title": "Shipping address same as billing",
"defaultValue": "true"
},
{
"type": "comment",
"name": "shipping-address",
"title": "Shipping address",
"enableIf": "{shipping-same-as-billing} = false",
"resetValueIf": "{shipping-same-as-billing} = false",
"setValueIf": "{shipping-same-as-billing} = true",
"setValueExpression": "{billing-address}",
"rows": 2
}
],
"showQuestionNumbers": "off",
"textUpdateMode": "onTyping"
};
let survey = new SurveyModel(json);
let comment1 = survey.getQuestionByName("billing-address") as QuestionCommentModel;
let comment2 = survey.getQuestionByName("shipping-address") as QuestionCommentModel;
let boolQuestion = survey.getQuestionByName("shipping-same-as-billing");
const textArea1 = document.createElement("textarea");
const textArea2 = document.createElement("textarea");
comment1.textAreaModel.setElement(textArea1);
comment2.textAreaModel.setElement(textArea2);

assert.equal(comment1.value, undefined, "commnet 1 value #1");
assert.equal(comment2.value, undefined, "commnet 2 value #1");
assert.equal(boolQuestion.value, true, "boolQuestion value #1");
assert.equal(textArea1.value, "", "textArea 1 value #1");
assert.equal(textArea2.value, "", "textArea 2 value #1");

comment1.value = "test";
assert.equal(comment1.value, "test", "commnet 1 value #2");
assert.equal(comment2.value, "test", "commnet 2 value #2");
assert.equal(boolQuestion.value, true, "boolQuestion value #2");
assert.equal(textArea1.value, "test", "textArea 1 value #2");
assert.equal(textArea2.value, "test", "textArea 2 value #2");

boolQuestion.value = false;
assert.equal(comment1.value, "test", "commnet 1 value #3");
assert.equal(comment2.value, undefined, "commnet 2 value #3");
assert.equal(boolQuestion.value, false, "boolQuestion value #3");
assert.equal(textArea1.value, "test", "textArea 1 value #3");
assert.equal(textArea2.value, "", "textArea 2 value #3");

textArea1.remove();
textArea2.remove();
});

0 comments on commit d44bd03

Please sign in to comment.