Skip to content

Commit 211a2b9

Browse files
committed
fix(editor): shouldn't call cell changed when cell value is undefined
- we were already checking for null value but undefined is another possibility, so now it checks for null/undefined in isValueChanged() method
1 parent 53cc371 commit 211a2b9

12 files changed

+30
-19
lines changed

src/app/modules/angular-slickgrid/editors/__tests__/autoCompleteEditor.spec.ts

+3
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ describe('AutoCompleteEditor', () => {
200200
const event = new (window.window as any).KeyboardEvent('keydown', { keyCode: KEY_CHAR_A, bubbles: true, cancelable: true });
201201

202202
editor = new AutoCompleteEditor(editorArguments);
203+
editor.setValue('z');
203204
const editorElm = divContainer.querySelector<HTMLInputElement>('input.editor-gender');
204205

205206
editorElm.focus();
@@ -362,6 +363,7 @@ describe('AutoCompleteEditor', () => {
362363
const spy = jest.spyOn(gridStub.getEditorLock(), 'commitCurrentEdit');
363364

364365
editor = new AutoCompleteEditor(editorArguments);
366+
editor.setValue('a');
365367
editor.save();
366368

367369
expect(spy).toHaveBeenCalled();
@@ -372,6 +374,7 @@ describe('AutoCompleteEditor', () => {
372374
const spy = jest.spyOn(editorArguments, 'commitChanges');
373375

374376
editor = new AutoCompleteEditor(editorArguments);
377+
editor.setValue('a');
375378
editor.save();
376379

377380
expect(spy).toHaveBeenCalled();

src/app/modules/angular-slickgrid/editors/__tests__/dualInputEditor.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ describe('DualInputEditor', () => {
224224
const event = new (window.window as any).KeyboardEvent('keydown', { keyCode: KEY_CHAR_0, bubbles: true, cancelable: true });
225225

226226
editor = new DualInputEditor(editorArguments);
227+
editor.setValues(['9', '9']);
227228
const editorElm = divContainer.querySelector<HTMLInputElement>('input.editor-range');
228229

229230
editor.focus();

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

+1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ describe('FloatEditor', () => {
178178
const event = new (window.window as any).KeyboardEvent('keydown', { keyCode: KEY_CHAR_0, bubbles: true, cancelable: true });
179179

180180
editor = new FloatEditor(editorArguments);
181+
editor.setValue(9);
181182
const editorElm = divContainer.querySelector<HTMLInputElement>('input.editor-price');
182183

183184
editor.focus();

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

+1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ describe('IntegerEditor', () => {
178178
const event = new (window.window as any).KeyboardEvent('keydown', { keyCode: KEY_CHAR_0, bubbles: true, cancelable: true });
179179

180180
editor = new IntegerEditor(editorArguments);
181+
editor.setValue(9);
181182
const editorElm = divContainer.querySelector<HTMLInputElement>('input.editor-price');
182183

183184
editor.focus();

src/app/modules/angular-slickgrid/editors/__tests__/longTextEditor.spec.ts

+2
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ describe('LongTextEditor', () => {
212212
const event = new (window.window as any).KeyboardEvent('keydown', { keyCode: KEY_CHAR_A, bubbles: true, cancelable: true });
213213

214214
editor = new LongTextEditor(editorArguments);
215+
editor.setValue('z');
215216
const editorElm = document.body.querySelector<HTMLTextAreaElement>('.editor-title textarea');
216217

217218
editor.focus();
@@ -237,6 +238,7 @@ describe('LongTextEditor', () => {
237238
const event = new (window.window as any).KeyboardEvent('keydown', { keyCode: KeyCode.ENTER, bubbles: true, cancelable: true });
238239

239240
editor = new LongTextEditor(editorArguments);
241+
editor.setValue('a');
240242
const editorElm = document.body.querySelector<HTMLTextAreaElement>('.editor-title textarea');
241243

242244
editor.focus();

src/app/modules/angular-slickgrid/editors/__tests__/textEditor.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ describe('TextEditor', () => {
186186
const event = new (window.window as any).KeyboardEvent('keydown', { keyCode: KEY_CHAR_A, bubbles: true, cancelable: true });
187187

188188
editor = new TextEditor(editorArguments);
189+
editor.setValue('z');
189190
const editorElm = divContainer.querySelector<HTMLInputElement>('input.editor-title');
190191

191192
editor.focus();

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,12 @@ export class AutoCompleteEditor implements Editor {
157157
}
158158

159159
isValueChanged(): boolean {
160-
const lastEvent = this._lastInputEvent && this._lastInputEvent.keyCode;
161-
if (this.columnEditor && this.columnEditor.alwaysSaveOnEnterKey && lastEvent === KeyCode.ENTER) {
160+
const elmValue = this._$editorElm.val();
161+
const lastKeyEvent = this._lastInputEvent && this._lastInputEvent.keyCode;
162+
if (this.columnEditor && this.columnEditor.alwaysSaveOnEnterKey && lastKeyEvent === KeyCode.ENTER) {
162163
return true;
163164
}
164-
return (!(this._$editorElm.val() === '' && this._defaultTextValue === null)) && (this._$editorElm.val() !== this._defaultTextValue);
165+
return (!(elmValue === '' && (this._defaultTextValue === null || this._defaultTextValue === undefined))) && (elmValue !== this._defaultTextValue);
165166
}
166167

167168
loadValue(item: any) {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ export class DualInputEditor implements Editor {
237237
if ((leftEditorParams && leftEditorParams.alwaysSaveOnEnterKey || rightEditorParams && rightEditorParams.alwaysSaveOnEnterKey) && lastKeyEvent === KeyCode.ENTER) {
238238
return true;
239239
}
240-
const leftResult = (!(leftElmValue === '' && this.originalLeftValue === null)) && (leftElmValue !== this.originalLeftValue);
241-
const rightResult = (!(rightElmValue === '' && this.originalRightValue === null)) && (rightElmValue !== this.originalRightValue);
240+
const leftResult = (!(leftElmValue === '' && (this.originalLeftValue === null || this.originalLeftValue === undefined))) && (leftElmValue !== this.originalLeftValue);
241+
const rightResult = (!(rightElmValue === '' && (this.originalRightValue === null || this.originalRightValue === undefined))) && (rightElmValue !== this.originalRightValue);
242242
return leftResult || rightResult;
243243
}
244244

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,13 @@ export class FloatEditor implements Editor {
130130
}
131131
}
132132

133-
isValueChanged() {
133+
isValueChanged(): boolean {
134134
const elmValue = this._$input.val();
135-
const lastEvent = this._lastInputEvent && this._lastInputEvent.keyCode;
136-
if (this.columnEditor && this.columnEditor.alwaysSaveOnEnterKey && lastEvent === KeyCode.ENTER) {
135+
const lastKeyEvent = this._lastInputEvent && this._lastInputEvent.keyCode;
136+
if (this.columnEditor && this.columnEditor.alwaysSaveOnEnterKey && lastKeyEvent === KeyCode.ENTER) {
137137
return true;
138138
}
139-
return (!(elmValue === '' && this.originalValue === null)) && (elmValue !== this.originalValue);
139+
return (!(elmValue === '' && (this.originalValue === null || this.originalValue === undefined))) && (elmValue !== this.originalValue);
140140
}
141141

142142
loadValue(item: any) {

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,13 @@ export class IntegerEditor implements Editor {
104104
}
105105
}
106106

107-
isValueChanged() {
107+
isValueChanged(): boolean {
108108
const elmValue = this._$input.val();
109-
const lastEvent = this._lastInputEvent && this._lastInputEvent.keyCode;
110-
if (this.columnEditor && this.columnEditor.alwaysSaveOnEnterKey && lastEvent === KeyCode.ENTER) {
109+
const lastKeyEvent = this._lastInputEvent && this._lastInputEvent.keyCode;
110+
if (this.columnEditor && this.columnEditor.alwaysSaveOnEnterKey && lastKeyEvent === KeyCode.ENTER) {
111111
return true;
112112
}
113-
return (!(elmValue === '' && this.originalValue === null)) && (elmValue !== this.originalValue);
113+
return (!(elmValue === '' && (this.originalValue === null || this.originalValue === undefined))) && (elmValue !== this.originalValue);
114114
}
115115

116116
loadValue(item: any) {

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,9 @@ export class LongTextEditor implements Editor {
159159
}
160160
}
161161

162-
isValueChanged() {
163-
return (!(this._$textarea.val() === '' && this.defaultValue === null)) && (this._$textarea.val() !== this.defaultValue);
162+
isValueChanged(): boolean {
163+
const elmValue = this._$textarea.val();
164+
return (!(elmValue === '' && (this.defaultValue === null || this.defaultValue === undefined))) && (elmValue !== this.defaultValue);
164165
}
165166

166167
loadValue(item: any) {

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,13 @@ export class TextEditor implements Editor {
104104
}
105105
}
106106

107-
isValueChanged() {
107+
isValueChanged(): boolean {
108108
const elmValue = this._$input.val();
109-
const lastEvent = this._lastInputEvent && this._lastInputEvent.keyCode;
110-
if (this.columnEditor && this.columnEditor.alwaysSaveOnEnterKey && lastEvent === KeyCode.ENTER) {
109+
const lastKeyEvent = this._lastInputEvent && this._lastInputEvent.keyCode;
110+
if (this.columnEditor && this.columnEditor.alwaysSaveOnEnterKey && lastKeyEvent === KeyCode.ENTER) {
111111
return true;
112112
}
113-
return (!(elmValue === '' && this.originalValue === null)) && (elmValue !== this.originalValue);
113+
return (!(elmValue === '' && (this.originalValue === null || this.originalValue === undefined))) && (elmValue !== this.originalValue);
114114
}
115115

116116
loadValue(item: any) {

0 commit comments

Comments
 (0)