Skip to content

Commit

Permalink
Fix editor value being lost when window loses focus
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
msssk committed Jun 19, 2020
1 parent 1e93bb1 commit 7b8f4ae
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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'});
}
Expand Down Expand Up @@ -662,6 +667,8 @@ define([
}
}

self._updatePropertyFromEditor(column, cmp, {type: 'widget'});

var parentNode = rootNode.parentNode,
options = { alreadyHooked: true },
cell = self.cell(rootNode),
Expand Down

0 comments on commit 7b8f4ae

Please sign in to comment.