Giter Club home page Giter Club logo

Comments (3)

mbabauer avatar mbabauer commented on June 25, 2024

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):

  1. Lines 6 and 9 of my AutoForm hooks code above (on the CfsAutoForm.Hooks.beforeInsert and on the return line.
  2. In cfs_autoform.js lines 123, 127, 134, and 137 (increment doneFiles, increment failedFiles, call to deepFind, and call to deepSet. 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:

  1. Form is submitted
  2. Break on line 6 of AutoForm.hooks: CfsAutoForm.Hooks.beforeInsert.call(this, doc);
  3. Call to line 9 of AutoForm.hooks: return doc;
  4. Note: At this point, doc has no fileIds set
  5. This repeats like 3 or 4 times (break on line 6 followed by break on line 9 of AutoForm.Hooks)
  6. Server console writes out my console.log for the ">>>> creating: ...", but doc does not contain any fileIds
  7. File save output shows up in Server logs (I have debug turned on) indicating the files were finally saved
  8. 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.

mbabauer avatar mbabauer commented on June 25, 2024

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.

mbabauer avatar mbabauer commented on June 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.