From 7b8f4ae22958516e2f904d041f92989c96b2e41e Mon Sep 17 00:00:00 2001 From: Mangala SSS Khalsa Date: Thu, 18 Jun 2020 22:44:35 -0700 Subject: [PATCH] Fix editor value being lost when window loses focus Problem can be observed in 'test/Editor_more_widgets.html': 1. Click a cell in the "Select Store" column 2. Change the value in the select 3. Activate a different application (causing the browser to lose focus) Result: the edited cell reverts to its previous value and Grid.js throws an error in Grid#cell() This change fixes the focus event handling for this scenario. --- Editor.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Editor.js b/Editor.js index 457bdf736..5bcd4d4ab 100644 --- a/Editor.js +++ b/Editor.js @@ -30,7 +30,12 @@ define([ this.on('.dgrid-input:focusin', function () { self._focusedEditorCell = self.cell(this); }); - this._editorFocusoutHandle = on.pausable(this.domNode, '.dgrid-input:focusout', function () { + this._editorFocusoutHandle = on.pausable(this.domNode, '.dgrid-input:focusout', function (event) { + // Widgets can trigger a 'focusout' event when clicking within the widget, since the widget + // is still focused the 'focusout' event should be ignored + if (self._focusedEditorCell && self._focusedEditorCell.element.contains(event.target)) { + return; + } self._focusedEditorCell = null; }); this._listeners.push(this._editorFocusoutHandle); @@ -530,10 +535,10 @@ define([ }) ); } - else { - // For editOn editors, connect to onBlur rather than onChange, since - // the latter is delayed by setTimeouts in Dijit and will fire too late. - cmp.on(editOn ? 'blur' : 'change', function () { + else if (!editOn) { + // For editOn editors the update is handled in the shared editor's blur handler since + // the 'change' event is delayed by setTimeouts in Dijit and will fire too late. + cmp.on('change', function () { if (!cmp._dgridIgnoreChange) { self._updatePropertyFromEditor(column, cmp, {type: 'widget'}); } @@ -662,6 +667,8 @@ define([ } } + self._updatePropertyFromEditor(column, cmp, {type: 'widget'}); + var parentNode = rootNode.parentNode, options = { alreadyHooked: true }, cell = self.cell(rootNode),