From cee955b0d03e9a33b341345b0395caf5a0629266 Mon Sep 17 00:00:00 2001 From: Andrew Telnov Date: Mon, 27 Nov 2023 15:35:32 +0200 Subject: [PATCH] Default Value Expression overrides the survey.data values with v1.9.107 and newer fix #7423 --- src/question.ts | 2 +- tests/surveytests.ts | 46 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/question.ts b/src/question.ts index b9aa009870..3228d9c61a 100644 --- a/src/question.ts +++ b/src/question.ts @@ -2290,7 +2290,7 @@ export class Question extends SurveyElement this.updateValueFromSurveyCore(newValue, this.isTwoValueEquals(newValue, val)); }); } else { - this.updateValueFromSurveyCore(newValue, isEmpty); + this.updateValueFromSurveyCore(newValue, this.data !== this.getSurvey()); } this.updateDependedQuestions(); this.updateIsAnswered(); diff --git a/tests/surveytests.ts b/tests/surveytests.ts index 685e24c49d..874bf99b07 100644 --- a/tests/surveytests.ts +++ b/tests/surveytests.ts @@ -18268,3 +18268,49 @@ QUnit.test("Expression bug with complex path, #7396", function (assert) { q2.value = { "16": 2 }; assert.equal(q3.isVisible, true, "visible #3"); }); +QUnit.test("Do not run defaultValueExpression on survey.data, #7423", function (assert) { + const survey = new SurveyModel({ + elements: [ + { + type: "text", + name: "q1", + defaultValueExpression: "value1" + }, + { + type: "text", + name: "q2", + defaultValueExpression: "value2" + }, + { + type: "checkbox", + name: "q3", + choices: ["item1", "item2", "item3"], + defaultValueExpression: "['item1', 'item3']" + }, + { + type: "dropdown", + name: "q4", + choices: ["item1", "item2", "item3"], + defaultValueExpression: "item2" + } + ] + }); + const q1 = survey.getQuestionByName("q1"); + const q2 = survey.getQuestionByName("q2"); + const q3 = survey.getQuestionByName("q3"); + const q4 = survey.getQuestionByName("q4"); + assert.equal(q1.value, "value1", "q1.value #1"); + assert.equal(q2.value, "value2", "q2.value #1"); + assert.deepEqual(q3.value, ["item1", "item3"], "q3.value #1"); + assert.equal(q4.value, "item2", "q4.value #1"); + survey.data = { q1: "val1" }; + assert.equal(q1.value, "val1", "q1.value #2"); + assert.notOk(q2.value, "q2.value #2"); + assert.deepEqual(q3.value, [], "q3.value #2"); + assert.notOk(q4.value, "q4.value #2"); + q2.value = "val2"; + assert.equal(q1.value, "val1", "q1.value #3"); + assert.equal(q2.value, "val2", "q2.value #3"); + assert.deepEqual(q3.value, [], "q3.value #3"); + assert.notOk(q4.value, "q4.value #3"); +}); \ No newline at end of file