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

Commit 71c5ff9

Browse files
authored
Merge pull request #209 from ghiscoding/fix/editor-integer
fix(editor): integer editor was always showing invalid when null value
2 parents 045e1ba + 0eb1f32 commit 71c5ff9

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/app/modules/angular-slickgrid/editors/floatEditor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class FloatEditor implements Editor {
3030
}
3131

3232
get hasAutoCommitEdit() {
33-
return this.args.grid.getOptions().autoCommitEdit;
33+
return this.args && this.args.grid && this.args.grid.getOptions && this.args.grid.getOptions().autoCommitEdit;
3434
}
3535

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

7474
getColumnEditor() {
75-
return this.args && this.args.column && this.args.column.internalColumnEditor && this.args.column.internalColumnEditor;
75+
return this.args && this.args.column && this.args.column.internalColumnEditor;
7676
}
7777

7878
getDecimalPlaces(): number {

src/app/modules/angular-slickgrid/editors/integerEditor.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class IntegerEditor implements Editor {
2828
}
2929

3030
get hasAutoCommitEdit() {
31-
return this.args.grid.getOptions().autoCommitEdit;
31+
return this.args && this.args.grid && this.args.grid.getOptions && this.args.grid.getOptions().autoCommitEdit;
3232
}
3333

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

7272
getColumnEditor() {
73-
return this.args && this.args.column && this.args.column.internalColumnEditor && this.args.column.internalColumnEditor;
73+
return this.args && this.args.column && this.args.column.internalColumnEditor;
7474
}
7575

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

8282
if (item && this.columnDef && (item.hasOwnProperty(fieldName) || item.hasOwnProperty(fieldNameFromComplexObject))) {
83-
this.defaultValue = parseInt(item[fieldNameFromComplexObject || fieldName], 10);
83+
this.defaultValue = item[fieldNameFromComplexObject || fieldName];
8484
this.$input.val(this.defaultValue);
8585
this.$input[0].defaultValue = this.defaultValue;
8686
this.$input.select();
@@ -92,7 +92,7 @@ export class IntegerEditor implements Editor {
9292
if (elmValue === '' || isNaN(elmValue)) {
9393
return elmValue;
9494
}
95-
return parseInt(elmValue, 10) || 0;
95+
return isNaN(elmValue) ? elmValue : parseInt(elmValue, 10);
9696
}
9797

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

106106
isValueChanged() {
107107
const elmValue = this.$input.val();
108-
const value = isNaN(elmValue) ? elmValue : parseInt(elmValue, 10);
109108
const lastEvent = this._lastInputEvent && this._lastInputEvent.keyCode;
110-
111109
if (this.columnEditor && this.columnEditor.alwaysSaveOnEnterKey && lastEvent === KeyCode.ENTER) {
112110
return true;
113111
}
114-
return (!(value === '' && this.defaultValue === null && lastEvent !== KeyCode.ENTER)) && (value !== this.defaultValue);
112+
return (!(elmValue === '' && this.defaultValue === null)) && (elmValue !== this.defaultValue);
115113
}
116114

117115
save() {

0 commit comments

Comments
 (0)