diff --git a/packages/survey-core/src/question_matrixdynamic.ts b/packages/survey-core/src/question_matrixdynamic.ts index 7e341c2c70..05dd44d7ac 100644 --- a/packages/survey-core/src/question_matrixdynamic.ts +++ b/packages/survey-core/src/question_matrixdynamic.ts @@ -149,7 +149,7 @@ export class QuestionMatrixDynamicModel extends QuestionMatrixDropdownModelBase /** * If it is not empty, then this value is set to every new row, including rows created initially, unless the defaultValue is not empty * @see defaultValue - * @see defaultValueFromLastRow + * @see copyDefaultValueFromLastEntry */ public get defaultRowValue(): any { return this.getPropertyValue("defaultRowValue"); @@ -163,11 +163,21 @@ export class QuestionMatrixDynamicModel extends QuestionMatrixDropdownModelBase * If you also specify `defaultValue`, it will be merged with the copied values. * @see defaultValue */ + public get copyDefaultValueFromLastEntry(): boolean { + return this.getPropertyValue("copyDefaultValueFromLastEntry"); + } + public set copyDefaultValueFromLastEntry(val: boolean) { + this.setPropertyValue("copyDefaultValueFromLastEntry", val); + } + /** + * Obsolete. Use the [`copyDefaultValueFromLastEntry`](https://surveyjs.io/form-library/documentation/api-reference/dynamic-matrix-table-question-model#copyDefaultValueFromLastEntry) property instead. + * @deprecated + */ public get defaultValueFromLastRow(): boolean { - return this.getPropertyValue("defaultValueFromLastRow"); + return this.copyDefaultValueFromLastEntry; } public set defaultValueFromLastRow(val: boolean) { - this.setPropertyValue("defaultValueFromLastRow", val); + this.copyDefaultValueFromLastEntry = val; } protected isDefaultValueEmpty(): boolean { return ( @@ -562,7 +572,7 @@ export class QuestionMatrixDynamicModel extends QuestionMatrixDropdownModelBase (res)[key] = this.defaultRowValue[key]; } } - if (isRowAdded && this.defaultValueFromLastRow) { + if (isRowAdded && this.copyDefaultValueFromLastEntry) { var val = this.value; if (!!val && Array.isArray(val) && val.length >= this.rowCount - 1) { var rowValue = val[this.rowCount - 2]; @@ -1014,7 +1024,7 @@ Serializer.addClass( }, { name: "keyName" }, "defaultRowValue:rowvalue", - "defaultValueFromLastRow:boolean", + { name: "copyDefaultValueFromLastEntry:boolean", alternativeName: "defaultValueFromLastRow" }, { name: "confirmDelete:boolean" }, { name: "confirmDeleteText", diff --git a/packages/survey-core/tests/question_matrixdynamictests.ts b/packages/survey-core/tests/question_matrixdynamictests.ts index 56873410b3..b18198d2ab 100644 --- a/packages/survey-core/tests/question_matrixdynamictests.ts +++ b/packages/survey-core/tests/question_matrixdynamictests.ts @@ -2959,7 +2959,7 @@ QUnit.test( } ); -QUnit.test("Test defaultValueFromLastRow property", function (assert) { +QUnit.test("Test copyDefaultValueFromLastEntry property", function (assert) { var survey = new SurveyModel(); var page = survey.addNewPage("page"); var question = ( @@ -2970,7 +2970,7 @@ QUnit.test("Test defaultValueFromLastRow property", function (assert) { question.addColumn("col1"); question.addColumn("col2"); question.addColumn("col3"); - question.defaultValueFromLastRow = true; + question.copyDefaultValueFromLastEntry = true; question.addRow(); question.visibleRows; assert.equal(question.isEmpty(), true, "It is empty"); @@ -2982,7 +2982,7 @@ QUnit.test("Test defaultValueFromLastRow property", function (assert) { { col1: 1, col2: 2 }, { col1: 1, col2: 2 }, ], - "defaultValueFromLastRow is working" + "copyDefaultValueFromLastEntry is working" ); question.defaultRowValue = { col1: 11, col3: 3 }; question.addRow(); @@ -2993,7 +2993,7 @@ QUnit.test("Test defaultValueFromLastRow property", function (assert) { { col1: 1, col2: 2 }, { col1: 1, col2: 2, col3: 3 }, ], - "defaultValueFromLastRow is merging with defaultRowValue" + "copyDefaultValueFromLastEntry is merging with defaultRowValue" ); }); @@ -6719,14 +6719,14 @@ QUnit.test("Detail panel, run conditions & matrix before elements, bug#9137", fu assert.equal(panel.getQuestionByName("q1").isVisible, true, "first question is visible, #3"); assert.equal(panel.getQuestionByName("q2").isVisible, true, "second question is visible, #3"); }); -QUnit.test("Detail panel and defaultValueFromLastRow", function (assert) { +QUnit.test("Detail panel and copyDefaultValueFromLastEntry", function (assert) { var survey = new SurveyModel({ elements: [ { type: "matrixdynamic", name: "matrix", detailPanelMode: "underRow", - defaultValueFromLastRow: true, + copyDefaultValueFromLastEntry: true, detailElements: [{ type: "text", name: "q1" }], rowCount: 1, columns: [ diff --git a/packages/survey-core/tests/surveytests.ts b/packages/survey-core/tests/surveytests.ts index 39bb62c366..1908ecbf41 100644 --- a/packages/survey-core/tests/surveytests.ts +++ b/packages/survey-core/tests/surveytests.ts @@ -6155,7 +6155,7 @@ QUnit.test("onMatrixRowAdded", function (assert) { assert.equal(q1.rowCount, 3, "there are 3 rows"); assert.equal(q1.value[2]["col1"], 2, "get value from previous"); }); -QUnit.test("onMatrixRowAdded + defaultValueFromLastRow", function (assert) { +QUnit.test("onMatrixRowAdded + copyDefaultValueFromLastEntry", function (assert) { var survey = new SurveyModel(); var visibleRowsCount = -1; survey.onMatrixRowAdded.add(function (sender, options) { @@ -6164,7 +6164,7 @@ QUnit.test("onMatrixRowAdded + defaultValueFromLastRow", function (assert) { }); var page = survey.addNewPage("Page 1"); var q1 = new QuestionMatrixDynamicModel("matrixdynamic"); - q1.defaultValueFromLastRow = true; + q1.copyDefaultValueFromLastEntry = true; page.addElement(q1); q1.addColumn("col1"); q1.addColumn("col2");