From e25fe9aef65f9204a0911a16ab149b1e06f5ca74 Mon Sep 17 00:00:00 2001 From: Mangala SSS Khalsa Date: Thu, 14 May 2020 18:50:47 -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 b30c3595b..fddf11cfb 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); @@ -573,10 +578,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'}); } @@ -716,6 +721,8 @@ define([ } } + self._updatePropertyFromEditor(column, cmp, {type: 'widget'}); + var parentNode = rootNode.parentNode, options = { alreadyHooked: true }, cell = self.cell(rootNode);