Skip to content

Commit 924cd9b

Browse files
Portugal, Marcelomportuga
Portugal, Marcelo
authored andcommitted
fix(gridEdit): Fixing issues with focus and grid edit.
Changing some instances of applyAsync back to timeout.
1 parent e594a07 commit 924cd9b

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/features/edit/js/gridEdit.js

+11-14
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,9 @@
534534

535535
cellNavNavigateDereg = uiGridCtrl.grid.api.cellNav.on.navigate($scope, function (newRowCol, oldRowCol, evt) {
536536
if ($scope.col.colDef.enableCellEditOnFocus) {
537+
// Don't begin edit if the cell hasn't changed
537538
if (newRowCol.row === $scope.row && newRowCol.col === $scope.col && evt && (evt.type === 'click' || evt.type === 'keydown')) {
538-
$scope.$applyAsync(function () {
539+
$timeout(function() {
539540
beginEdit(evt);
540541
});
541542
}
@@ -834,8 +835,8 @@
834835
});
835836

836837
$scope.$broadcast(uiGridEditConstants.events.BEGIN_CELL_EDIT, triggerEvent);
837-
$scope.$applyAsync(function () {
838-
// execute in a apply async to give any complex editor templates a cycle to completely render
838+
$timeout(function () {
839+
// execute in a timeout to give any complex editor templates a cycle to completely render
839840
$scope.grid.api.edit.raise.beginCellEdit($scope.row.entity, $scope.col.colDef, triggerEvent);
840841
});
841842
}
@@ -935,7 +936,8 @@
935936

936937
//set focus at start of edit
937938
$scope.$on(uiGridEditConstants.events.BEGIN_CELL_EDIT, function (evt,triggerEvent) {
938-
$scope.$applyAsync(function () {
939+
// must be in a timeout since it requires a new digest cycle
940+
$timeout(function () {
939941
$elm[0].focus();
940942
//only select text if it is not being replaced below in the cellNav viewPortKeyPress
941943
if ($elm[0].select && ($scope.col.colDef.enableCellEditOnFocus || !(uiGridCtrl && uiGridCtrl.grid.api.cellNav))) {
@@ -1136,8 +1138,8 @@
11361138
*
11371139
*/
11381140
module.directive('uiGridEditDropdown',
1139-
['uiGridConstants', 'uiGridEditConstants',
1140-
function (uiGridConstants, uiGridEditConstants) {
1141+
['uiGridConstants', 'uiGridEditConstants', '$timeout',
1142+
function (uiGridConstants, uiGridEditConstants, $timeout) {
11411143
return {
11421144
require: ['?^uiGrid', '?^uiGridRenderContainer'],
11431145
scope: true,
@@ -1152,7 +1154,7 @@
11521154

11531155
//set focus at start of edit
11541156
$scope.$on(uiGridEditConstants.events.BEGIN_CELL_EDIT, function () {
1155-
$scope.$applyAsync(function(){
1157+
$timeout(function(){
11561158
$elm[0].focus();
11571159
});
11581160

@@ -1234,12 +1236,7 @@
12341236

12351237
},
12361238
post: function ($scope, $elm, $attrs, controllers) {
1237-
var uiGridCtrl, renderContainerCtrl;
1238-
if (controllers[0]) { uiGridCtrl = controllers[0]; }
1239-
if (controllers[1]) { renderContainerCtrl = controllers[1]; }
1240-
var grid = uiGridCtrl.grid;
1241-
1242-
var handleFileSelect = function( event ){
1239+
function handleFileSelect(event) {
12431240
var target = event.srcElement || event.target;
12441241

12451242
if (target && target.files && target.files.length > 0) {
@@ -1290,7 +1287,7 @@
12901287
} else {
12911288
$scope.$emit(uiGridEditConstants.events.CANCEL_CELL_EDIT);
12921289
}
1293-
};
1290+
}
12941291

12951292
$elm[0].addEventListener('change', handleFileSelect, false);
12961293

0 commit comments

Comments
 (0)