Skip to content

Commit

Permalink
Increase the dynamicMatrix.rowCount if value array length exceed the …
Browse files Browse the repository at this point in the history
…current rowCount: #194
  • Loading branch information
andrewtelnov committed Jan 23, 2017
1 parent a49f9cf commit faa9a89
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/question_matrixdropdownbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,12 @@ export class QuestionMatrixDropdownModelBase extends Question implements IMatrix
}
return result;
}
protected onBeforeValueChanged(val: any) {
}
protected onValueChanged() {
if (this.isRowChanging || !(this.generatedVisibleRows) || this.generatedVisibleRows.length == 0) return;
if (this.isRowChanging) return;
this.onBeforeValueChanged(this.value);
if(!(this.generatedVisibleRows) || this.generatedVisibleRows.length == 0) return;
this.isRowChanging = true;
var val = this.createNewValue(this.value);
for (var i = 0; i < this.generatedVisibleRows.length; i++) {
Expand Down
8 changes: 8 additions & 0 deletions src/question_matrixdynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ export class QuestionMatrixDynamicModel extends QuestionMatrixDropdownModelBase
protected createMatrixRow(value: any): MatrixDynamicRowModel {
return new MatrixDynamicRowModel(this.rowCounter ++, this, value);
}
protected onBeforeValueChanged(val: any) {
var newRowCount = val && Array.isArray(val) ? val.length : 0;
if (newRowCount <= this.rowCount) return;
this.rowCountValue = newRowCount;
if (this.generatedVisibleRows) {
this.generatedVisibleRows = this.visibleRows;
}
}
protected createNewValue(curValue: any): any {
var result = curValue;
if (!result) result = [];
Expand Down
13 changes: 13 additions & 0 deletions tests/surveyquestiontests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,19 @@ QUnit.test("Matrixdynamic hasOther column", function (assert) {
rows[0].cells[0].question.value = "other";
assert.equal(question.hasErrors(), true, "Should set other value");
});
QUnit.test("Matrixdynamic adjust rowCount on setting the value", function (assert) {
var question = new QuestionMatrixDynamicModel("matrixDymanic");
question.rowCount = 0;
question.columns.push(new MatrixDropdownColumn("column1"));
question.columns.push(new MatrixDropdownColumn("column2"));
question.value = [{}, { 'column1': 2 }, {}];
assert.equal(question.rowCount, 3, "It should be 3 rowCount");
var rows = question.visibleRows;
question.value = [{}, { 'column1': 2 }, {}, {}];
assert.equal(question.rowCount, 4, "It should be 4 rowCount");
question.value = [{ 'column1': 2 }];
assert.equal(question.rowCount, 4, "Keep row count equals 4");
});
QUnit.test("Matrixdropdown different cell types", function (assert) {
var question = new QuestionMatrixDropdownModel("matrixDropdown");

Expand Down

0 comments on commit faa9a89

Please sign in to comment.