Skip to content

Be more defensive in $scope.$on('fileuploaddone') to perhaps avoid ve… #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions app/fng-jq-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@

$scope.$on('fileuploaddone', function (event, data) {
const field = $scope.dataField(true);
// $scope.dataField(true) should always return something, but have seen a case in Sentry where it did not.
// surely a very rare case where they cancelled / redirected etc. at a very inopportune moment
if (!field) {
return;
}
const fileDetails = data.result.files[0];
const _id = fileDetails.id;
const filename = fileDetails.name;
Expand All @@ -327,9 +332,11 @@
// urls for downloading, deleting and retrieving a thumbnail for this item as setUpAttachments() isn't
// called again here
const queue = $scope.$$childHead.queue;
addAttachmentUrls(queue[queue.length - 1], location, _id, filename, thumbnailId);
$scope.ngModel.$setDirty();
assignQueueToFormScope();
if (queue) {
addAttachmentUrls(queue[queue.length - 1], location, _id, filename, thumbnailId);
$scope.ngModel.$setDirty();
assignQueueToFormScope();
}
});
},
])
Expand Down
15 changes: 11 additions & 4 deletions dist/fng-jq-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@

$scope.$on('fileuploaddone', function (event, data) {
const field = $scope.dataField(true);
// $scope.dataField(true) should always return something, but have seen a case in Sentry where it did not.
// surely a very rare case where they cancelled / redirected etc. at a very inopportune moment
if (!field) {
return;
}
const fileDetails = data.result.files[0];
const _id = fileDetails.id;
const filename = fileDetails.name;
Expand All @@ -327,11 +332,13 @@
// urls for downloading, deleting and retrieving a thumbnail for this item as setUpAttachments() isn't
// called again here
const queue = $scope.$$childHead.queue;
addAttachmentUrls(queue[queue.length - 1], location, _id, filename, thumbnailId);
$scope.ngModel.$setDirty();
assignQueueToFormScope();
if (queue) {
addAttachmentUrls(queue[queue.length - 1], location, _id, filename, thumbnailId);
$scope.ngModel.$setDirty();
assignQueueToFormScope();
}
});
},
}
])
.directive('fngJqUploadForm', [
'PluginHelperService',
Expand Down
Loading
Loading