Skip to content

Commit

Permalink
Matrix Dynamic: Rename defaultValueFromLastRow fix #5110 (#9238)
Browse files Browse the repository at this point in the history
* Matrix Dynamic: Rename defaultValueFromLastRow fix #5110

* Update the deprecation message

---------

Co-authored-by: RomanTsukanov <[email protected]>
  • Loading branch information
andrewtelnov and RomanTsukanov authored Jan 7, 2025
1 parent 1308da4 commit d2fbde2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
20 changes: 15 additions & 5 deletions packages/survey-core/src/question_matrixdynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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 (
Expand Down Expand Up @@ -562,7 +572,7 @@ export class QuestionMatrixDynamicModel extends QuestionMatrixDropdownModelBase
(<any>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];
Expand Down Expand Up @@ -1014,7 +1024,7 @@ Serializer.addClass(
},
{ name: "keyName" },
"defaultRowValue:rowvalue",
"defaultValueFromLastRow:boolean",
{ name: "copyDefaultValueFromLastEntry:boolean", alternativeName: "defaultValueFromLastRow" },
{ name: "confirmDelete:boolean" },
{
name: "confirmDeleteText",
Expand Down
12 changes: 6 additions & 6 deletions packages/survey-core/tests/question_matrixdynamictests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <QuestionMatrixDynamicModel>(
Expand All @@ -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");
Expand All @@ -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();
Expand All @@ -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"
);
});

Expand Down Expand Up @@ -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: [
Expand Down
4 changes: 2 additions & 2 deletions packages/survey-core/tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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");
Expand Down

0 comments on commit d2fbde2

Please sign in to comment.