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 d8bb856 commit de304ec
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 @@ -257,10 +257,10 @@ function createEditor(column){
}
});
}
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.connect(cmp, editOn ? "onBlur" : "onChange", 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.connect(cmp, "onChange", function(){
if(!cmp._dgridIgnoreChange){
setPropertyFromEditor(grid, cmp, {type: "widget"});
}
Expand Down Expand Up @@ -365,6 +365,8 @@ function createSharedEditor(column, originalRenderCell){
}
}

setPropertyFromEditor(grid, cmp, {type: 'widget'});

var parentNode = rootNode.parentNode,
i = parentNode.children.length - 1,
options = { alreadyHooked: true },
Expand Down Expand Up @@ -596,7 +598,12 @@ return function(column, editor, editOn){
grid._focusedEditorCell = grid.cell(this);
}));
focusoutHandle = grid._editorFocusoutHandle =
on.pausable(grid.domNode, '.dgrid-input:focusout', function () {
on.pausable(grid.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 (grid._focusedEditorCell && grid._focusedEditorCell.element.contains(event.target)) {
return;
}
grid._focusedEditorCell = null;
});
listeners.push(focusoutHandle);
Expand Down

0 comments on commit de304ec

Please sign in to comment.