Skip to content
This repository has been archived by the owner on Mar 25, 2020. It is now read-only.

improved handling of multiple files #28

Open
wants to merge 1 commit into
base: master
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
6 changes: 2 additions & 4 deletions cfs-autoform-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,11 @@ Hooks = {
// or push it into the array of IDs if it's a multiple files field.
else {
if (arrayFields[key]) {
CfsAutoForm.Util.deepFind(doc,key).push(fileObj._id);
CfsAutoForm.Util.deepPush(doc, key, fileObj._id);
} else {
//doc[key] = fileObj._id;
CfsAutoForm.Util.deepSet(doc,key,fileObj._id);
}
}

// If this is the last file to be processed, pass execution back to autoform
if (doneFiles === totalFiles) {
// If any files failed
Expand All @@ -89,7 +87,6 @@ Hooks = {
}
}
}

// Loop through all hidden file fields, inserting
// and uploading all files that have been attached to them.
template.$('.cfsaf-hidden').each(function () {
Expand Down Expand Up @@ -118,6 +115,7 @@ Hooks = {
uploadedFiles.push(fileObj);
elem.data("cfsaf_uploaded-files", uploadedFiles);
// call callback

cb(null, fileObj, key);
});

Expand Down
9 changes: 8 additions & 1 deletion cfs-autoform-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ Util = {
delete obj[prop];
});
},
deepPush: function(obj, prop, value){
return CfsAutoForm.Util.deepDo(obj,prop, function(obj, prop){
if(!obj[prop]){
obj[prop] = [];
}
obj[prop].push(value);
})
},
deepSet: function(obj, prop, value){
return CfsAutoForm.Util.deepDo(obj, prop, function(obj, prop){
obj[prop] = value;
Expand All @@ -16,7 +24,6 @@ Util = {
path = path.split('.');
for (i = 0; i < path.length - 1; i++)
obj = obj[path[i]];

return obj;
},
//executes closure(obj, prop) where prop might be a string of properties and array indices
Expand Down