Getting document _id in autoform update

Hi all,

I posted this question on Stackoverflow but I haven’t received any answers and I’m pulling my hair out, so I hope it’s okay to post here…

I’m using aldeed autoform for a multi-step registration form on my site. What I’m trying to figure out is how to connect each step so that they update the same document.

Here’s my first form (truncated), which inserts a document into the UserDetails collection. This form is working fine.

{{#autoForm collection="UserDetails" id="userdetails" type="insert"}} <fieldset class="form-group"> {{> afFieldInput name='name'}} {{> afFieldInput name='surname'}} {{> afFieldInput name='email'}} </fieldset> <button class="btn btn-primary" type="submit">Update</button> {{/autoForm}}

Here’s the hook for the first form:

AutoForm.addHooks("userdetails", { onSuccess: function() { Session.set("currentUserDetailsID",this.docId); } });

As you can see, I’m setting a session variable, which I’m using via a helper to set the doc of my second form, which is used to update some extra fields in the document inserted with the first form. Here is the second form (truncated):

{{#autoForm collection="UserDetails" id="userdetails2" type="update" doc=selectedUser}} <fieldset class="form-group"> {{> afFieldInput name='address1'}} </fieldset> <button class="btn btn-primary" type="submit">Update</button> {{/autoForm}}

I know that the Session variable is working because if I use {{selectedUser}} in my template it shows me the correct document id. However, when I submit the above form, it’s not updating the collection and I can’t trace anything in its callback hook:

AutoForm.addHooks("userdetails2", { onSuccess: function() { var addr = this.address1; console.log(addr); //this and any other value traces as undefined... } });

Any idea where I’m going wrong? Am I confused about how to pass the document id to the second part of the form?

Thanks!

you can try to pass doc from before uodate hook.

before: {
    // Replace `formType` with the form `type` attribute to which this hook applies
    formType: function(doc) {
      // Potentially alter the doc
      doc.foo = 'bar';

      // Then return it or pass it to this.result()
      //return doc; (synchronous)
      this.result(doc); (asynchronous)
    }
  },
onSuccess: function(formType, result) {},

Thanks theara,

I’m not 100% sure I understand your reply - I’m a bit of a meteor newbie…

Can you elaborate on where in my code I would insert the before callback? Also, when it says replace ‘formtype’ with the form ‘type’ attribute, I would replace it with ‘update’, right?

Sorry if I sound very confused, but I’m struggling to get my head around this stuff…

A

It is right update.