Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The default value of a custom specialized component is not saved to s… #5957

Merged
merged 1 commit into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/question_custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,6 @@ export abstract class QuestionCustomModelBase extends Question
getSurveyData(): ISurveyData {
return this;
}
// getSurvey(): ISurvey {
// return this.survey;
// }
getTextProcessor(): ITextProcessor {
return this.textProcessor;
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions tests/question_customtests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down