Skip to content

Commit

Permalink
Fix field profile directive for file input type
Browse files Browse the repository at this point in the history
  • Loading branch information
wwelling committed Aug 29, 2024
1 parent 567786a commit daab08b
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/main/webapp/app/directives/fieldProfileDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ vireo.directive("field", function ($controller, $filter, $q, $timeout, Controlle
}

$scope.hasFile = function (fieldValue) {
return fieldValue !== undefined && fieldValue.fieldPredicate.documentTypePredicate && fieldValue.value && fieldValue.value.length > 0;
return fieldValue !== undefined && fieldValue.id && fieldValue.fieldPredicate.documentTypePredicate && fieldValue.value && fieldValue.value.length > 0;
};

$scope.addFieldValue = function () {
Expand Down Expand Up @@ -285,12 +285,11 @@ vireo.directive("field", function ($controller, $filter, $q, $timeout, Controlle

$scope.cancel = function (fieldValue) {
$scope.submission.removeUnsavedFieldValue(fieldValue);
refreshFieldValues();
if ($scope.fieldValues.length === 0) {
$scope.addFieldValue();
refreshFieldValues();
$scope.previewing = false;
}
refreshFieldValues();
$scope.previewing = false;
};

$scope.getPreview = function (fieldValue) {
Expand Down Expand Up @@ -339,13 +338,17 @@ vireo.directive("field", function ($controller, $filter, $q, $timeout, Controlle
FileUploadService.removeFile($scope.submission, fieldValue).then(function (removed) {
$scope.deleting = false;
$scope.previewing = false;
if(removed) {
if (removed) {
delete fieldValue.id;
delete fieldValue.file;
delete fieldValue.value;
if (!$scope.profile.repeatable) {
$scope.addFieldValue();
}
}

$scope.submission.removeUnsavedFieldValue(fieldValue);

refreshFieldValues();
$scope.closeModal();
});
Expand Down Expand Up @@ -408,6 +411,7 @@ vireo.directive("field", function ($controller, $filter, $q, $timeout, Controlle
$scope.fieldValues = $filter('fieldValuePerProfile')($scope.submission.fieldValues, $scope.profile.fieldPredicate);
$scope.fieldValue = $scope.fieldValues[0];

$scope.hasFiles = false;
for (var i in $scope.fieldValues) {
if ($scope.hasFile($scope.fieldValues[i])) {
$scope.hasFiles = true;
Expand Down

0 comments on commit daab08b

Please sign in to comment.