From ff64f09ba5e47bc029a1023186df5d301ef2ea98 Mon Sep 17 00:00:00 2001 From: Aleksey Novikov Date: Mon, 7 Apr 2025 12:25:07 +0300 Subject: [PATCH 1/3] #9691 Add method that maps survey data to fieldset JSON Fixes #9691 --- packages/survey-core/src/survey.ts | 10 +++++- packages/survey-core/tests/surveytests.ts | 40 +++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/packages/survey-core/src/survey.ts b/packages/survey-core/src/survey.ts index fa94921290..c9c21a7f00 100644 --- a/packages/survey-core/src/survey.ts +++ b/packages/survey-core/src/survey.ts @@ -3161,6 +3161,14 @@ export class SurveyModel extends SurveyElementCore this.valuesHash = {}; this.setDataCore(data, !data); } + public calcWithExpressionMap(map: any) { + const data = this.data; + const res = {}; + Object.keys(map).forEach(key => { + res[key] = new ExpressionRunner(map[key]).run(data); + }); + return res; + } /** * Merges a specified data object with the object from the [`data`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#data) property. * @@ -8188,7 +8196,7 @@ export class SurveyModel extends SurveyElementCore const advHeader = layoutElement && layoutElement.data as Cover; if (this.showTOC && !(advHeader && advHeader.hasBackground)) { if (container === "center") { - containerLayoutElements.push(layoutElement); + containerLayoutElements.push(layoutElement); } } else { if (layoutElement.container === container) { diff --git a/packages/survey-core/tests/surveytests.ts b/packages/survey-core/tests/surveytests.ts index 251cf86d11..becd6303c6 100644 --- a/packages/survey-core/tests/surveytests.ts +++ b/packages/survey-core/tests/surveytests.ts @@ -21986,3 +21986,43 @@ QUnit.test("Don't rise onPageAdded when mooving question", function (assert) { assert.equal(pageAddedRaisedCount, 0, "onPageAdded is not raised"); assert.equal(survey.pages[0].name, "page2", "page2 is the first page"); }); +QUnit.only("test calcWithExpressionMap function", function (assert) { + var survey = new SurveyModel({ + "pages": [ + { + "name": "page1", + "elements": [ + { + "type": "text", + "name": "question1" + }, + { + "type": "text", + "name": "question2" + } + ] + } + ] + }); + assert.deepEqual(survey.data, {}, "there is no data"); + survey.data = { question1: "item1", question2: 5 }; + assert.deepEqual( + survey.data, + { question1: "item1", question2: 5 }, + "set the object" + ); + + const map = { + "f1": "{question1}", + "f2": "{question2}", + "f1_1": "question1" + }; + + const mappedData = survey.calcWithExpressionMap(map); + + assert.deepEqual( + mappedData, + { f1: "item1", f2: 5, f1_1: "question1" }, + "set the object" + ); +}); \ No newline at end of file From bc7e9a4dc4643664217868307f5794a15e62f257 Mon Sep 17 00:00:00 2001 From: Aleksey Novikov Date: Tue, 8 Apr 2025 17:57:19 +0300 Subject: [PATCH 2/3] #9691 Add method that maps survey data to fieldset JSON Fixes #9691 --- packages/survey-core/src/survey.ts | 19 +++++++- packages/survey-core/tests/surveytests.ts | 59 ++++++++++++++++++++++- 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/packages/survey-core/src/survey.ts b/packages/survey-core/src/survey.ts index c9c21a7f00..6f7b200a46 100644 --- a/packages/survey-core/src/survey.ts +++ b/packages/survey-core/src/survey.ts @@ -3165,7 +3165,24 @@ export class SurveyModel extends SurveyElementCore const data = this.data; const res = {}; Object.keys(map).forEach(key => { - res[key] = new ExpressionRunner(map[key]).run(data); + const mapValue = (typeof (map[key]) === "object") ? map[key] : { expr: map[key] } as any; + const val = new ExpressionRunner(mapValue.expr).run(data); + let newVal = null; + if (typeof (mapValue.values) === "object") { + if (Array.isArray(mapValue.values)) { + newVal = mapValue.values.indexOf(val) >= 0; + } else { + newVal = mapValue.values[val]; + } + } + else { + if (mapValue.values === undefined) { + newVal = val; + } else { + newVal = mapValue.values == val; + } + } + res[key] = newVal; }); return res; } diff --git a/packages/survey-core/tests/surveytests.ts b/packages/survey-core/tests/surveytests.ts index becd6303c6..66a22a4b4e 100644 --- a/packages/survey-core/tests/surveytests.ts +++ b/packages/survey-core/tests/surveytests.ts @@ -22014,7 +22014,9 @@ QUnit.only("test calcWithExpressionMap function", function (assert) { const map = { "f1": "{question1}", - "f2": "{question2}", + "f2": { + expr: "{question2}" + }, "f1_1": "question1" }; @@ -22025,4 +22027,57 @@ QUnit.only("test calcWithExpressionMap function", function (assert) { { f1: "item1", f2: 5, f1_1: "question1" }, "set the object" ); -}); \ No newline at end of file +}); + +QUnit.skip("test calcWithExpressionMap function for radio and checkboxes", function (assert) { + var survey = new SurveyModel({ + "pages": [ + { + "name": "page1", + "elements": [ + { + "type": "radiogroup", + "name": "question1", + "choiсes": ["item1", "item2", "item3"] + }, + { + "type": "checkboxes", + "name": "question2", + "choiсes": ["item1", "item2", "item3"] + } + ] + } + ] + }); + survey.data = { question1: "item1", question2: ["item1", "item3"] }; + + const map = { + "f1": { + expr: "{question1}", + values: { + "item1": "1", + "item2": "2", + "item3": "3" + } + }, + "f2_1": { + expr: "{question2}", + values: ["item1"] + }, + "f2_2": { + expr: "{question2}", + values: ["item2"] + }, + "f2_3": { + expr: "{question2}", + values: "item3" + } + }; + + const mappedData = survey.calcWithExpressionMap(map); + + assert.deepEqual( + mappedData, + { f1: "1", f2_1: true, f2_2: false, f2_3: true }, + ); +}); From 7e31839d951a096654340e99469e4b1f4fb327ae Mon Sep 17 00:00:00 2001 From: Aleksey Novikov Date: Wed, 9 Apr 2025 00:20:01 +0300 Subject: [PATCH 3/3] #9670 Dropdown on mobile - search editor visibility Fixes #9670 --- packages/survey-core/src/survey.ts | 8 ++------ packages/survey-core/tests/surveytests.ts | 8 ++++---- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/survey-core/src/survey.ts b/packages/survey-core/src/survey.ts index 6f7b200a46..1ff7fb098a 100644 --- a/packages/survey-core/src/survey.ts +++ b/packages/survey-core/src/survey.ts @@ -3169,17 +3169,13 @@ export class SurveyModel extends SurveyElementCore const val = new ExpressionRunner(mapValue.expr).run(data); let newVal = null; if (typeof (mapValue.values) === "object") { - if (Array.isArray(mapValue.values)) { - newVal = mapValue.values.indexOf(val) >= 0; - } else { - newVal = mapValue.values[val]; - } + newVal = mapValue.values[val]; } else { if (mapValue.values === undefined) { newVal = val; } else { - newVal = mapValue.values == val; + newVal = Array.isArray(val) ? val.indexOf(mapValue.values) >= 0 : mapValue.values == val; } } res[key] = newVal; diff --git a/packages/survey-core/tests/surveytests.ts b/packages/survey-core/tests/surveytests.ts index 66a22a4b4e..fac47c0bd7 100644 --- a/packages/survey-core/tests/surveytests.ts +++ b/packages/survey-core/tests/surveytests.ts @@ -21986,7 +21986,7 @@ QUnit.test("Don't rise onPageAdded when mooving question", function (assert) { assert.equal(pageAddedRaisedCount, 0, "onPageAdded is not raised"); assert.equal(survey.pages[0].name, "page2", "page2 is the first page"); }); -QUnit.only("test calcWithExpressionMap function", function (assert) { +QUnit.test("test calcWithExpressionMap function", function (assert) { var survey = new SurveyModel({ "pages": [ { @@ -22029,7 +22029,7 @@ QUnit.only("test calcWithExpressionMap function", function (assert) { ); }); -QUnit.skip("test calcWithExpressionMap function for radio and checkboxes", function (assert) { +QUnit.test("test calcWithExpressionMap function for radio and checkboxes", function (assert) { var survey = new SurveyModel({ "pages": [ { @@ -22062,11 +22062,11 @@ QUnit.skip("test calcWithExpressionMap function for radio and checkboxes", funct }, "f2_1": { expr: "{question2}", - values: ["item1"] + values: "item1" }, "f2_2": { expr: "{question2}", - values: ["item2"] + values: "item2" }, "f2_3": { expr: "{question2}",