Skip to content

Commit

Permalink
regression: valuePrepareFunction is applied to undefined values from …
Browse files Browse the repository at this point in the history
…the "newRow" row

It is crazy that the "newRow" row is created before the user clicked on the ADD button. This regression was a lot harder to debug that it should be... phew...
  • Loading branch information
uap-universe committed Aug 9, 2023
1 parent d57e557 commit d6cc0ad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 8 additions & 2 deletions projects/angular2-smart-table/src/lib/lib/data-set/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ export class Cell {

constructor(protected value: unknown, protected row: Row, protected column: Column) {
this.cachedValue = this.value;
this.cachedPreparedValue = this.getPreparedValue();
this.newValue = this.cachedPreparedValue;
if (this.row.index >= 0) {
this.cachedPreparedValue = this.getPreparedValue();
this.newValue = this.cachedPreparedValue;
} else {
// we must not call the valuePrepareFunction on freshly created rows that do not contain defined data
this.cachedPreparedValue = '';
this.newValue = '';
}
}

getColumn(): Column {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class DataSet {
constructor(data: Array<any> = [], protected columnSettings: IColumns) {
this.createColumns(columnSettings);
this.setData(data);

// TODO: fix that the "new row" is always created, even when the table is not even configured to add new rows
this.createNewRow();
}

Expand Down Expand Up @@ -171,6 +171,9 @@ export class DataSet {
}

createNewRow() {
// TODO: the empty object is invalid data in general and is very likely breaking almost every other function
// in particular, custom valuePrepareFunction can explode (see the related hack in the Cell's constructor)
// we should some day fix this by defining a valueCreateFunction that can create a reasonable default object
this.newRow = new Row(-1, {}, this);
this.newRow.isInEditing = true;
}
Expand Down

0 comments on commit d6cc0ad

Please sign in to comment.