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!