Skip to content

Commit

Permalink
Merge pull request #8687 from surveyjs/bug/8686-titlelocation-left-de…
Browse files Browse the repository at this point in the history
…lete

The Uncaught TypeError: Cannot read properties of null exception occu…
  • Loading branch information
andrewtelnov authored Aug 14, 2024
2 parents 59dd2a2 + d18f930 commit a69d667
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/survey-core/src/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ export class Question extends SurveyElement<Question>
}
}
public get titleWidth(): string {
if (this.getTitleLocation() === "left") {
if (this.parent && this.getTitleLocation() === "left") {
const columns = this.parent.getColumsForElement(this as any);
const columnCount = columns.length;
if (columnCount !== 0 && !!columns[0].questionTitleWidth) return columns[0].questionTitleWidth;
Expand Down
13 changes: 13 additions & 0 deletions packages/survey-core/tests/layout_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,19 @@ QUnit.test("columns generate - title width", function (assert) {
assert.deepEqual(q3.titleWidth, "12.5%");
assert.deepEqual(q4.titleWidth, "25%");
});
QUnit.test("title width & titleLocation left & delete question, #8686", function (assert) {
const surveyModel = new SurveyModel({
elements: [{
name: "q1",
type: "text",
titleLocation: "left"
}]
});
const page = surveyModel.pages[0];
const q1 = surveyModel.getQuestionByName("q1");
q1.delete();
assert.notOk(q1.titleWidth);
});

QUnit.test("user columns de/serialization", function (assert) {
const surveyModel = new SurveyModel({
Expand Down
40 changes: 40 additions & 0 deletions testCafe/survey/questionTitlePattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,43 @@ frameworks.forEach(framework => {
await t.expect(joinElementInnerText("h5", 1)).eql("# (b) q1");
});
});

const json2 = {
elements: [
{
type: "comment",
name: "q1",
titleLocation: "left"
},
{
type: "text",
name: "q2",
titleLocation: "left"
},
{
type: "text",
name: "q3",
titleLocation: "left"
}
]
};

frameworks.forEach(framework => {
fixture`${framework} ${title}`.page`${url}${framework}`.beforeEach(
async t => {
await initSurvey(framework, json2);
}
);

const deleteQuestion = ClientFunction(name => {
window["survey"].getQuestionByName(name).delete();
});

test("Delete questions with title location equals to left", async t => {
await deleteQuestion("q1");
await deleteQuestion("q2");
await t.expect(Selector("h5").find("span").withText("q1").exists).notOk();
await t.expect(Selector("h5").find("span").withText("q2").exists).notOk();
await t.expect(Selector("h5").find("span").withText("q3").exists).ok();
});
});

0 comments on commit a69d667

Please sign in to comment.