Skip to content

Commit

Permalink
fix creator
Browse files Browse the repository at this point in the history
  • Loading branch information
OlgaLarina committed Jun 9, 2023
1 parent bb34d68 commit 5124f76
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/survey-element.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { property } from "./jsonobject";
import { JsonObjectProperty, Serializer, property } from "./jsonobject";
import { RendererFactory } from "./rendererFactory";
import { Base } from "./base";
import { Action, IAction } from "./actions/action";
Expand Down Expand Up @@ -61,11 +61,16 @@ export abstract class SurveyElementCore extends Base implements ILocalizableOwne
*/
@property({
localizable: true, onSet: (newDescription, self) => {
self.updateDescriptionVisibility(self, newDescription);
self.updateDescriptionVisibility(newDescription);
}
}) description: string;
public updateDescriptionVisibility(newDescription: any) {
this.hasDescription = !!newDescription;
let showPlaceholder = false;
if(this.isDesignMode) {
const property: JsonObjectProperty = Serializer.findProperty(this.getType(), "description");
showPlaceholder = !!(property?.placeholder);
}
this.hasDescription = !!newDescription || showPlaceholder;
}

get locDescription(): LocalizableString {
Expand Down Expand Up @@ -629,7 +634,7 @@ export class SurveyElement<E = any> extends SurveyElementCore implements ISurvey
if (!this.survey) {
this.onSurveyLoad();
}
this.hasDescription = !!this.description;
this.updateDescriptionVisibility(this.description);
}
public setVisibleIndex(index: number): number {
return 0;
Expand Down
29 changes: 29 additions & 0 deletions tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15907,6 +15907,35 @@ QUnit.test("hasDescription is not updated on changing locale", function (assert)
assert.equal(question.hasDescription, true, "Question description is shown for 'de'");
survey.locale = "";
});
QUnit.test("hasDescription is isDesignMode", function (assert) {
const commentDescriptionProperty = Serializer.getProperty("comment", "description");
const oldValue = commentDescriptionProperty.placeholder;
commentDescriptionProperty.placeholder = "Q placeholder";

const survey = new SurveyModel({});
survey["_isDesignMode"] = true;
settings.supportCreatorV2 = true;
survey.fromJSON({
pages: [{
name: "page1",
title: "Page title",
elements: [{
type: "text",
name: "q1",
}, {
type: "comment",
name: "q2",
}]
}]
});
const q1 = survey.getQuestionByName("q1");
const q2 = survey.getQuestionByName("q2");
assert.notOk(q1.hasDescription, "text description is not shown");
assert.ok(q2.hasDescription, "comment description is shown");

commentDescriptionProperty.placeholder = oldValue;
settings.supportCreatorV2 = false;
});
QUnit.test("Test survey with custom type", function (assert) {
JsonObject.metaData.addClass(
"sortablelist",
Expand Down

0 comments on commit 5124f76

Please sign in to comment.