Skip to content

Commit

Permalink
Fixed surveyjs/private-tasks#366 - KO: Survey doesn't have title and …
Browse files Browse the repository at this point in the history
…description if loaded via SurveyID (#7819)

Co-authored-by: tsv2013 <[email protected]>
  • Loading branch information
tsv2013 and tsv2013 authored Feb 7, 2024
1 parent 9514687 commit cd09a5d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,8 @@ export class SurveyModel extends SurveyElementCore
component: "sv-action-bar",
data: this.navigationBar
});

this.locTitle.onStringChanged.add(() => this.titleIsEmpty = this.locTitle.isEmpty);
}
processClosedPopup(question: IQuestion, popupModel: PopupModel<any>): void {
throw new Error("Method not implemented.");
Expand Down Expand Up @@ -2084,9 +2086,10 @@ export class SurveyModel extends SurveyElementCore
return new CssClassBuilder().append(this.css.logo)
.append(logoClasses[this.logoPosition]).toString();
}
@property({ defaultValue: true }) private titleIsEmpty: boolean;
public get renderedHasTitle(): boolean {
if (this.isDesignMode) return this.isPropertyVisible("title");
return !this.locTitle.isEmpty && this.showTitle;
return !this.titleIsEmpty && this.showTitle;
}
public get renderedHasDescription(): boolean {
if (this.isDesignMode) return this.isPropertyVisible("description");
Expand Down Expand Up @@ -6113,6 +6116,7 @@ export class SurveyModel extends SurveyElementCore
this.updateRenderBackgroundImage();
this.updateCurrentPage();
this.hasDescription = !!this.description;
this.titleIsEmpty = this.locTitle.isEmpty;
this.setCalculatedWidthModeUpdater();
}

Expand Down
14 changes: 13 additions & 1 deletion tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12428,6 +12428,7 @@ QUnit.test("Survey<=Base propertyValueChanged", function (assert) {
var survey = new SurveyModel(json);
var counter = 0;

let log = "";
survey.onPropertyValueChangedCallback = (
name: string,
oldValue: any,
Expand All @@ -12436,13 +12437,14 @@ QUnit.test("Survey<=Base propertyValueChanged", function (assert) {
arrayChanges: ArrayChanges
) => {
counter++;
log += "->" + name;
};

assert.equal(counter, 0, "initial");

survey.title = "new";

assert.equal(counter, 1, "callback called");
assert.equal(log, "->title", "callback called for title");
});

QUnit.test(
Expand Down Expand Up @@ -15020,13 +15022,23 @@ QUnit.test("Test survey renderedHasTitle/renderedHasLogo properties", function (
assert
) {
var survey = new SurveyModel();
assert.equal(
survey["titleIsEmpty"],
true,
"titleIsEmpty due to no title"
);
assert.equal(
survey.renderedHasHeader,
false,
"hasHeader, title and logo are invisible"
);
assert.equal(survey.renderedHasTitle, false, "There is not title");
survey.title = "title";
assert.equal(
survey["titleIsEmpty"],
false,
"titleIs not Empty due to title has been set"
);
assert.equal(survey.renderedHasTitle, true, "There is title");
assert.equal(survey.renderedHasHeader, true, "hasHeader, title is visible");
survey.showTitle = false;
Expand Down

0 comments on commit cd09a5d

Please sign in to comment.