diff --git a/packages/common/src/editors/__tests__/autoCompleteEditor.spec.ts b/packages/common/src/editors/__tests__/autoCompleteEditor.spec.ts index b3257fce1..e3f9ae4c9 100644 --- a/packages/common/src/editors/__tests__/autoCompleteEditor.spec.ts +++ b/packages/common/src/editors/__tests__/autoCompleteEditor.spec.ts @@ -203,6 +203,7 @@ describe('AutoCompleteEditor', () => { const event = new (window.window as any).KeyboardEvent('keydown', { keyCode: KEY_CHAR_A, bubbles: true, cancelable: true }); editor = new AutoCompleteEditor(editorArguments); + editor.setValue('z'); const editorElm = divContainer.querySelector('input.editor-gender'); editorElm.focus(); @@ -365,6 +366,7 @@ describe('AutoCompleteEditor', () => { const spy = jest.spyOn(gridStub.getEditorLock(), 'commitCurrentEdit'); editor = new AutoCompleteEditor(editorArguments); + editor.setValue('a'); editor.save(); expect(spy).toHaveBeenCalled(); @@ -375,6 +377,7 @@ describe('AutoCompleteEditor', () => { const spy = jest.spyOn(editorArguments, 'commitChanges'); editor = new AutoCompleteEditor(editorArguments); + editor.setValue('a'); editor.save(); expect(spy).toHaveBeenCalled(); diff --git a/packages/common/src/editors/__tests__/dualInputEditor.spec.ts b/packages/common/src/editors/__tests__/dualInputEditor.spec.ts index a3e82d99f..67be66f06 100644 --- a/packages/common/src/editors/__tests__/dualInputEditor.spec.ts +++ b/packages/common/src/editors/__tests__/dualInputEditor.spec.ts @@ -226,6 +226,7 @@ describe('DualInputEditor', () => { const event = new (window.window as any).KeyboardEvent('keydown', { keyCode: KEY_CHAR_0, bubbles: true, cancelable: true }); editor = new DualInputEditor(editorArguments); + editor.setValues(['9', '9']); const editorElm = divContainer.querySelector('input.editor-range'); editor.focus(); diff --git a/packages/common/src/editors/__tests__/floatEditor.spec.ts b/packages/common/src/editors/__tests__/floatEditor.spec.ts index 197ce7c2f..db68d1e32 100644 --- a/packages/common/src/editors/__tests__/floatEditor.spec.ts +++ b/packages/common/src/editors/__tests__/floatEditor.spec.ts @@ -179,6 +179,7 @@ describe('FloatEditor', () => { const event = new (window.window as any).KeyboardEvent('keydown', { keyCode: KEY_CHAR_0, bubbles: true, cancelable: true }); editor = new FloatEditor(editorArguments); + editor.setValue(9); const editorElm = divContainer.querySelector('input.editor-price'); editor.focus(); diff --git a/packages/common/src/editors/__tests__/integerEditor.spec.ts b/packages/common/src/editors/__tests__/integerEditor.spec.ts index d929fdff1..48fa1a6ac 100644 --- a/packages/common/src/editors/__tests__/integerEditor.spec.ts +++ b/packages/common/src/editors/__tests__/integerEditor.spec.ts @@ -180,6 +180,7 @@ describe('IntegerEditor', () => { const event = new (window.window as any).KeyboardEvent('keydown', { keyCode: KEY_CHAR_0, bubbles: true, cancelable: true }); editor = new IntegerEditor(editorArguments); + editor.setValue(9); const editorElm = divContainer.querySelector('input.editor-price'); editor.focus(); diff --git a/packages/common/src/editors/__tests__/longTextEditor.spec.ts b/packages/common/src/editors/__tests__/longTextEditor.spec.ts index cc467498d..4a61393a8 100644 --- a/packages/common/src/editors/__tests__/longTextEditor.spec.ts +++ b/packages/common/src/editors/__tests__/longTextEditor.spec.ts @@ -202,6 +202,7 @@ describe('LongTextEditor', () => { const event = new (window.window as any).KeyboardEvent('keydown', { keyCode: KEY_CHAR_A, bubbles: true, cancelable: true }); editor = new LongTextEditor(editorArguments); + editor.setValue('z'); const editorElm = document.body.querySelector('.editor-title textarea'); editor.focus(); @@ -227,6 +228,7 @@ describe('LongTextEditor', () => { const event = new (window.window as any).KeyboardEvent('keydown', { keyCode: KeyCode.ENTER, bubbles: true, cancelable: true }); editor = new LongTextEditor(editorArguments); + editor.setValue('a'); const editorElm = document.body.querySelector('.editor-title textarea'); editor.focus(); diff --git a/packages/common/src/editors/__tests__/textEditor.spec.ts b/packages/common/src/editors/__tests__/textEditor.spec.ts index e4fba5414..80caee05c 100644 --- a/packages/common/src/editors/__tests__/textEditor.spec.ts +++ b/packages/common/src/editors/__tests__/textEditor.spec.ts @@ -188,6 +188,7 @@ describe('TextEditor', () => { const event = new (window.window as any).KeyboardEvent('keydown', { keyCode: KEY_CHAR_A, bubbles: true, cancelable: true }); editor = new TextEditor(editorArguments); + editor.setValue('z'); const editorElm = divContainer.querySelector('input.editor-title'); editor.focus(); diff --git a/packages/common/src/editors/autoCompleteEditor.ts b/packages/common/src/editors/autoCompleteEditor.ts index 25d46ddae..c6d4b2d1d 100644 --- a/packages/common/src/editors/autoCompleteEditor.ts +++ b/packages/common/src/editors/autoCompleteEditor.ts @@ -159,11 +159,12 @@ export class AutoCompleteEditor implements Editor { } isValueChanged(): boolean { + const elmValue = this._$editorElm.val(); const lastKeyEvent = this._lastInputKeyEvent && this._lastInputKeyEvent.keyCode; if (this.columnEditor && this.columnEditor.alwaysSaveOnEnterKey && lastKeyEvent === KeyCode.ENTER) { return true; } - return (!(this._$editorElm.val() === '' && this._defaultTextValue === null)) && (this._$editorElm.val() !== this._defaultTextValue); + return (!(elmValue === '' && (this._defaultTextValue === null || this._defaultTextValue === undefined))) && (elmValue !== this._defaultTextValue); } loadValue(item: any) { diff --git a/packages/common/src/editors/dualInputEditor.ts b/packages/common/src/editors/dualInputEditor.ts index 616878f67..a7061b728 100644 --- a/packages/common/src/editors/dualInputEditor.ts +++ b/packages/common/src/editors/dualInputEditor.ts @@ -242,8 +242,8 @@ export class DualInputEditor implements Editor { if ((leftEditorParams && leftEditorParams.alwaysSaveOnEnterKey || rightEditorParams && rightEditorParams.alwaysSaveOnEnterKey) && lastKeyEvent === KeyCode.ENTER) { return true; } - const leftResult = (!(leftElmValue === '' && this.originalLeftValue === null)) && (leftElmValue !== this.originalLeftValue); - const rightResult = (!(rightElmValue === '' && this.originalRightValue === null)) && (rightElmValue !== this.originalRightValue); + const leftResult = (!(leftElmValue === '' && (this.originalLeftValue === null || this.originalLeftValue === undefined))) && (leftElmValue !== this.originalLeftValue); + const rightResult = (!(rightElmValue === '' && (this.originalRightValue === null || this.originalRightValue === undefined))) && (rightElmValue !== this.originalRightValue); return leftResult || rightResult; } diff --git a/packages/common/src/editors/floatEditor.ts b/packages/common/src/editors/floatEditor.ts index e8890cd80..6d7342fde 100644 --- a/packages/common/src/editors/floatEditor.ts +++ b/packages/common/src/editors/floatEditor.ts @@ -152,7 +152,7 @@ export class FloatEditor implements Editor { if (this.columnEditor && this.columnEditor.alwaysSaveOnEnterKey && lastKeyEvent === KeyCode.ENTER) { return true; } - return (!(elmValue === '' && this.originalValue === null)) && (elmValue !== this.originalValue); + return (!(elmValue === '' && (this.originalValue === null || this.originalValue === undefined))) && (elmValue !== this.originalValue); } loadValue(item: any) { diff --git a/packages/common/src/editors/integerEditor.ts b/packages/common/src/editors/integerEditor.ts index 8aa19c801..b525ddc62 100644 --- a/packages/common/src/editors/integerEditor.ts +++ b/packages/common/src/editors/integerEditor.ts @@ -129,7 +129,7 @@ export class IntegerEditor implements Editor { if (this.columnEditor && this.columnEditor.alwaysSaveOnEnterKey && lastKeyEvent === KeyCode.ENTER) { return true; } - return (!(elmValue === '' && this.originalValue === null)) && (elmValue !== this.originalValue); + return (!(elmValue === '' && (this.originalValue === null || this.originalValue === undefined))) && (elmValue !== this.originalValue); } loadValue(item: any) { diff --git a/packages/common/src/editors/longTextEditor.ts b/packages/common/src/editors/longTextEditor.ts index f10e60da7..ded31b24c 100644 --- a/packages/common/src/editors/longTextEditor.ts +++ b/packages/common/src/editors/longTextEditor.ts @@ -163,7 +163,8 @@ export class LongTextEditor implements Editor { } isValueChanged(): boolean { - return (!(this._$textarea.val() === '' && this.defaultValue === null)) && (this._$textarea.val() !== this.defaultValue); + const elmValue = this._$textarea.val(); + return (!(elmValue === '' && (this.defaultValue === null || this.defaultValue === undefined))) && (elmValue !== this.defaultValue); } loadValue(item: any) { diff --git a/packages/common/src/editors/textEditor.ts b/packages/common/src/editors/textEditor.ts index 578be5b9e..a5684376b 100644 --- a/packages/common/src/editors/textEditor.ts +++ b/packages/common/src/editors/textEditor.ts @@ -124,7 +124,7 @@ export class TextEditor implements Editor { if (this.columnEditor && this.columnEditor.alwaysSaveOnEnterKey && lastKeyEvent === KeyCode.ENTER) { return true; } - return (!(elmValue === '' && this.originalValue === null)) && (elmValue !== this.originalValue); + return (!(elmValue === '' && (this.originalValue === null || this.originalValue === undefined))) && (elmValue !== this.originalValue); } loadValue(item: any) { diff --git a/packages/vanilla-bundle/dist-grid-bundle-zip/slickgrid-vanilla-bundle.zip b/packages/vanilla-bundle/dist-grid-bundle-zip/slickgrid-vanilla-bundle.zip index e21405b93..afb5a5985 100644 Binary files a/packages/vanilla-bundle/dist-grid-bundle-zip/slickgrid-vanilla-bundle.zip and b/packages/vanilla-bundle/dist-grid-bundle-zip/slickgrid-vanilla-bundle.zip differ diff --git a/packages/web-demo-vanilla-bundle/src/examples/example03.ts b/packages/web-demo-vanilla-bundle/src/examples/example03.ts index ad3e64cf8..889cac419 100644 --- a/packages/web-demo-vanilla-bundle/src/examples/example03.ts +++ b/packages/web-demo-vanilla-bundle/src/examples/example03.ts @@ -68,6 +68,7 @@ export class Example3 { const gridContainerElm = document.querySelector(`.grid3`); gridContainerElm.addEventListener('onclick', this.handleOnClick.bind(this)); + gridContainerElm.addEventListener('oncellchange', this.handleOnCellChange.bind(this)); gridContainerElm.addEventListener('onvalidationerror', this.handleValidationError.bind(this)); gridContainerElm.addEventListener('onitemdeleted', this.handleItemDeleted.bind(this)); gridContainerElm.addEventListener('onslickergridcreated', this.handleOnSlickerGridCreated.bind(this)); @@ -372,6 +373,10 @@ export class Example3 { cost: (i % 33 === 0) ? null : Math.round(Math.random() * 10000) / 100, effortDriven: (i % 5 === 0) }; + + // if (i % 8) { + // delete tmpArray[i].duration; // test with undefined properties + // } } if (this.slickgridLwc) { this.slickgridLwc.dataset = tmpArray; @@ -479,6 +484,10 @@ export class Example3 { console.log('onClick', event.detail); } + handleOnCellChange(event) { + console.log('onCellChanged', event.detail); + } + handleValidationError(event) { console.log('handleValidationError', event.detail); const args = event.detail && event.detail.args;