From ca74e4830eeecb7ccf919d546d4105b8537fa907 Mon Sep 17 00:00:00 2001 From: tsv2013 Date: Mon, 15 Jan 2024 16:01:06 +0300 Subject: [PATCH] Fixed #7669 - Error during instantiating TOCModel for on creator preview (#7671) Co-authored-by: tsv2013 --- src/surveyToc.ts | 2 +- tests/surveyTOCTests.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/surveyToc.ts b/src/surveyToc.ts index ae87c58177..15d4381a62 100644 --- a/src/surveyToc.ts +++ b/src/surveyToc.ts @@ -41,7 +41,7 @@ export function createTOCListModel(survey: SurveyModel, onAction?: () => void) { } }, true, - items.filter(i => i.id === survey.currentPage.name)[0] || items.filter(i => i.id === pagesSource[0].name)[0] + items.filter(i => !!survey.currentPage && i.id === survey.currentPage.name)[0] || items.filter(i => i.id === pagesSource[0].name)[0] ); listModel.allowSelection = false; listModel.locOwner = survey; diff --git a/tests/surveyTOCTests.ts b/tests/surveyTOCTests.ts index d54c5b15b4..5f281f0af5 100644 --- a/tests/surveyTOCTests.ts +++ b/tests/surveyTOCTests.ts @@ -390,3 +390,11 @@ QUnit.test("survey.tryNavigateToPage", function (assert) { assert.equal(survey.currentPageNo, 3, "currentPageNo #6"); assert.deepEqual(pages, ["page2", "page1", "page3", "page1", "page4"], "Check onCurrentPageChanged"); }); +QUnit.test("TOC should be created for survey with no current page", function (assert) { + let json: any = { "logoPosition": "right", "pages": [{ "name": "page1", "elements": [{ "type": "panel", "name": "panel1", "width": "1180px" }] }] }; + const survey: SurveyModel = new SurveyModel(json); + assert.equal(survey.pages.length, 1); + assert.equal(survey.currentPageNo, -1); + const tocListModel = createTOCListModel(survey); + assert.ok(!!tocListModel, "TOC model should be created"); +});