Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

fix(editor): integer editor was always showing invalid when null value #209

Merged
merged 1 commit into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/app/modules/angular-slickgrid/editors/floatEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class FloatEditor implements Editor {
}

get hasAutoCommitEdit() {
return this.args.grid.getOptions().autoCommitEdit;
return this.args && this.args.grid && this.args.grid.getOptions && this.args.grid.getOptions().autoCommitEdit;
}

/** Get the Validator function, can be passed in Editor property or Column Definition */
Expand Down Expand Up @@ -72,7 +72,7 @@ export class FloatEditor implements Editor {
}

getColumnEditor() {
return this.args && this.args.column && this.args.column.internalColumnEditor && this.args.column.internalColumnEditor;
return this.args && this.args.column && this.args.column.internalColumnEditor;
}

getDecimalPlaces(): number {
Expand Down
12 changes: 5 additions & 7 deletions src/app/modules/angular-slickgrid/editors/integerEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class IntegerEditor implements Editor {
}

get hasAutoCommitEdit() {
return this.args.grid.getOptions().autoCommitEdit;
return this.args && this.args.grid && this.args.grid.getOptions && this.args.grid.getOptions().autoCommitEdit;
}

/** Get the Validator function, can be passed in Editor property or Column Definition */
Expand Down Expand Up @@ -70,7 +70,7 @@ export class IntegerEditor implements Editor {
}

getColumnEditor() {
return this.args && this.args.column && this.args.column.internalColumnEditor && this.args.column.internalColumnEditor;
return this.args && this.args.column && this.args.column.internalColumnEditor;
}

loadValue(item: any) {
Expand All @@ -80,7 +80,7 @@ export class IntegerEditor implements Editor {
const fieldNameFromComplexObject = fieldName.indexOf('.') ? fieldName.substring(0, fieldName.indexOf('.')) : '';

if (item && this.columnDef && (item.hasOwnProperty(fieldName) || item.hasOwnProperty(fieldNameFromComplexObject))) {
this.defaultValue = parseInt(item[fieldNameFromComplexObject || fieldName], 10);
this.defaultValue = item[fieldNameFromComplexObject || fieldName];
this.$input.val(this.defaultValue);
this.$input[0].defaultValue = this.defaultValue;
this.$input.select();
Expand All @@ -92,7 +92,7 @@ export class IntegerEditor implements Editor {
if (elmValue === '' || isNaN(elmValue)) {
return elmValue;
}
return parseInt(elmValue, 10) || 0;
return isNaN(elmValue) ? elmValue : parseInt(elmValue, 10);
}

applyValue(item: any, state: any) {
Expand All @@ -105,13 +105,11 @@ export class IntegerEditor implements Editor {

isValueChanged() {
const elmValue = this.$input.val();
const value = isNaN(elmValue) ? elmValue : parseInt(elmValue, 10);
const lastEvent = this._lastInputEvent && this._lastInputEvent.keyCode;

if (this.columnEditor && this.columnEditor.alwaysSaveOnEnterKey && lastEvent === KeyCode.ENTER) {
return true;
}
return (!(value === '' && this.defaultValue === null && lastEvent !== KeyCode.ENTER)) && (value !== this.defaultValue);
return (!(elmValue === '' && this.defaultValue === null)) && (elmValue !== this.defaultValue);
}

save() {
Expand Down