Comments (3)
After repeatedly looking at this, I wanted to share my findings with everyone so that I might get some help.
I started by putting breakpoints in the following places (I am using Chrome, if that matters):
- Lines 6 and 9 of my AutoForm hooks code above (on the
CfsAutoForm.Hooks.beforeInsert
and on thereturn
line. - In cfs_autoform.js lines 123, 127, 134, and 137 (increment
doneFiles
, incrementfailedFiles
, call todeepFind
, and call todeepSet
. This is where I believe the file IDs are set back to the document
I then modified my Meteor.method
to write out the document to console.log
like so:
Meteor.methods({
createNewAssignment: function(doc) {
console.log('>>>> creating: ', doc);
// Clean the doc to make sure any autoValues are done
Assignments.simpleSchema().clean(doc);
// Check the schema
check(doc, Assignments.simpleSchema());
doc._id = Assignments.insert(doc);
//... do some other stuff
return doc;
},
Here are the chain of events that occur:
- Form is submitted
- Break on line 6 of AutoForm.hooks:
CfsAutoForm.Hooks.beforeInsert.call(this, doc);
- Call to line 9 of AutoForm.hooks:
return doc;
- Note: At this point,
doc
has nofileIds
set - This repeats like 3 or 4 times (break on line 6 followed by break on line 9 of AutoForm.Hooks)
- Server console writes out my
console.log
for the ">>>> creating: ...", butdoc
does not contain anyfileIds
- File save output shows up in Server logs (I have debug turned on) indicating the files were finally saved
- Finally, after the
Meteor.method
ran in step 6 and the files are saved from step 7, I get a break on line 123 of cfs_autoform.js, followed by line 134, which again repeats a few times
I am not sure why the form seems to submit more than once, and that might possibly be the cause of all of this. However, what I can tell is that the cb
function defined on line 121 of cfs_autoform.js does not run until after the Meteor.method
is called to save the form values, and hence the fileIds
are not set on the object. It seems like that cb
method is getting called sometime later and so it's happening out of order with the rest of the process?
from meteor-cfs-autoform.
Ok, further information...it looks like the fileIds
are being set, but when the DDP request is sent over the filelds
array is empty again. I am investigating why this might be, but I have a console.log
right after I do clean()
, and the fileIds
are set as expected.
I am not sure why I saw issues with the timing. Best I can come up with is that my breakpoints might have caused the timing of the code to be off?
from meteor-cfs-autoform.
I figured things out. You can't call CfsAutoForm.Hooks.beforeInsert
and CfsAutoForm.Hooks.afterInsert
the way I was within your own hook. You have to define them as such:
Template.assignments.onRendered(function() {
AutoForm.hooks({
insertAssignmentsForm: {
before: {
method: CfsAutoForm.Hooks.beforeInsert
},
after: {
method: CfsAutoForm.Hooks.afterInsert
},
onError: function(formType, error) {
console.log('error: ', error);
},
onSuccess: function(formType, error) {
FlowRouter.go('/assignments/' + result.assignmentId);
}
}
});
});
When you do it the way I was prior using call()
you end up getting VERY funny results.
from meteor-cfs-autoform.
Related Issues (20)
- How do you add a before insert hook on this?
- Update for deeply nested cfs-file's broken HOT 2
- cfs-files (the multi version) does not work HOT 2
- Customize the ui "field" for multiple files
- this.template is undefined when before hook is a function HOT 1
- Exception in delivering result of invoking 'myServerMethod': Error: [[object Object]]
- file upload not working in IOS simulator
- Before hooks not work
- Not a valid enum value HOT 1
- Error on the exemple code
- File Validation
- How to add an image preview to the update page? HOT 1
- how to display images of a array?
- Validation bug
- How to restrict file type?
- AutoForm 6.0 support. HOT 2
- How to subscribe cfs-files
- Incompatiple when adding cfs:autoform
- update form!!!
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from meteor-cfs-autoform.