Skip to content

Commit

Permalink
Fix stackoverflow issue in Creator
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Dec 20, 2024
1 parent 1699b77 commit e3c4a3c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/survey-core/src/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1032,13 +1032,16 @@ export class Question extends SurveyElement<Question>
this.copyCssClasses(classes, css.question);
this.copyCssClasses(classes.error, css.error);
this.updateCssClasses(classes, css);
return classes;
}
protected onCalcCssClasses(classes: any): void {
super.onCalcCssClasses(classes);
if (this.survey) {
this.survey.updateQuestionCssClasses(this, classes);
}
if (this.onUpdateCssClassesCallback) {
this.onUpdateCssClassesCallback(classes);
}
return classes;
}
public get cssRoot(): string {
this.ensureElementCss();
Expand Down
2 changes: 2 additions & 0 deletions packages/survey-core/src/survey-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,9 +653,11 @@ export class SurveyElement<E = any> extends SurveyElementCore implements ISurvey
private createCssClassesValue(): any {
const res = this.calcCssClasses(this.css);
this.setPropertyValue("cssClassesValue", res);
this.onCalcCssClasses(res);
this.updateElementCssCore(this.cssClassesValue);
return res;
}
protected onCalcCssClasses(classes: any): void {}
/**
* Returns an object in which keys are UI elements and values are CSS classes applied to them.
*
Expand Down
24 changes: 24 additions & 0 deletions packages/survey-core/tests/question_customtests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3438,5 +3438,29 @@ QUnit.test("Dynamic serializable properties, bug#8852", function (assert) {
});
assert.notOk(survey.jsonErrors, "There is not errors");

ComponentCollection.Instance.clear();
});
QUnit.test("Composite: clearIfInvisible='onHidden'", function (assert) {
ComponentCollection.Instance.add({
name: "test",
elementsJSON: [
{ type: "text", name: "q1" },
{ type: "dropdown", name: "q2", choices: [1, 2, 3] },
{ type: "text", name: "q3", clearIfInvisible: "onHidden", visibleIf: "{composite.q2}=2" }
]
});
const survey = new SurveyModel({
elements: [
{ type: "test", name: "q1" }
]
});
const q1 = <QuestionCompositeModel>survey.getQuestionByName("q1");
q1.contentPanel.getQuestionByName("q1").value = "test1";
q1.contentPanel.getQuestionByName("q2").value = 2;
q1.contentPanel.getQuestionByName("q3").value = "abc";
assert.deepEqual(q1.value, { q1: "test1", q2: 2, q3: "abc" }, "test #1");
q1.contentPanel.getQuestionByName("q2").value = 3;
assert.deepEqual(q1.value, { q1: "test1", q2: 3 }, "test #1");

ComponentCollection.Instance.clear();
});
13 changes: 13 additions & 0 deletions packages/survey-core/tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6449,6 +6449,19 @@ QUnit.test("Question cssRoot", function (assert) {
"checkbox question root class"
);
});
QUnit.test("Question onUpdateQuestionCssClasses, modify question props", function (assert) {
const survey = new SurveyModel();
survey.onUpdateQuestionCssClasses.add(function (survey, options) {
options.question.titleLocation = "left";
});
survey.fromJSON({
elements: [
{ type: "text", name: "q1" },
],
});
const q1 = survey.getQuestionByName("q1");
assert.equal(q1.titleLocation, "left", "titleLocation is changed");
});

QUnit.test("Use send data to custom server", function (assert) {
var survey = twoPageSimplestSurvey();
Expand Down

0 comments on commit e3c4a3c

Please sign in to comment.