From 86b441fd40d285336edf61ded87bdacf227ef305 Mon Sep 17 00:00:00 2001 From: Andrew Telnov Date: Thu, 6 Apr 2023 21:26:57 +0300 Subject: [PATCH] The default value of a custom specialized component is not saved to survey results fixed #5954 --- src/question_custom.ts | 9 ++++++--- tests/question_customtests.ts | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/question_custom.ts b/src/question_custom.ts index b2ca706a47..138132c693 100644 --- a/src/question_custom.ts +++ b/src/question_custom.ts @@ -471,9 +471,6 @@ export abstract class QuestionCustomModelBase extends Question getSurveyData(): ISurveyData { return this; } - // getSurvey(): ISurvey { - // return this.survey; - // } getTextProcessor(): ITextProcessor { return this.textProcessor; } @@ -599,6 +596,12 @@ export class QuestionCustomModel extends QuestionCustomModelBase { if(this.isValueChanging(name, newValue)) return; super.setValue(name, newValue, locNotification, allowNotifyValueChanged); } + protected onSetData(): void { + super.onSetData(); + if (!!this.survey && !this.isEmpty()) { + this.setValue(this.name, this.value, false, this.allowNotifyValueChanged); + } + } public hasErrors(fireCallback: boolean = true, rec: any = null): boolean { if (!this.contentQuestion) return false; var res = this.contentQuestion.hasErrors(fireCallback, rec); diff --git a/tests/question_customtests.ts b/tests/question_customtests.ts index dfd339f44c..32ee260c0c 100644 --- a/tests/question_customtests.ts +++ b/tests/question_customtests.ts @@ -540,6 +540,7 @@ QUnit.test("Single: defaultValue", function (assert) { 2, "defaultValue is set for contentQuestion" ); + assert.deepEqual(survey.data, { q1: 2 }, "set data into survey"); ComponentCollection.Instance.clear(); }); QUnit.test("Composite: defaultValue", function (assert) { @@ -558,6 +559,7 @@ QUnit.test("Composite: defaultValue", function (assert) { var firstName = q.contentPanel.getQuestionByName("firstName"); assert.equal(firstName.value, "Jon", "firstName defaultValue"); assert.deepEqual(q.value, { firstName: "Jon" }, "question defaultValue"); + assert.deepEqual(survey.data, { q1: { firstName: "Jon" } }, "survey.data"); ComponentCollection.Instance.clear(); }); QUnit.test("Composite: defaultValue and survey in design mode", function (assert) {