I started using meteor some time ago in my new awesome project. I was struggling with forms and today found about this autoform plugin but it gives me exactly same errors as i had without it. I have created simple collection “posts”, posts_list that displays each post as well as modal windows with form that is used to add new posts. whenever i call method to create new post, I am getting exception while invoking method, missing key ‘title’.
my code looks somewhat like this (without pointless lines):
When trying to submit exact same thing via autoform, it ends up with same error and data is not added. +i am 100% sure fields have same type as defined in schema
In your effort to remove “pointless lines” you also removed the lines which define where #addPost is defined.
Also: A click handler gets the element you clicked on as a parameter. If this is not something like <form><input type="submit" id="addPost" /></form> your e.target won’t contain anything regarding the form.
nope, i found where was the problem. meteor couldn’t find values because if value is not submitted, its empty. For some reason meteor did not used e.target.fieldname hence empty value couldn’t be validated. i have changed to default js
var title = document.getElementById('title').value;
and it magically worked.
Looks like problem was just with e.target.title.value
Which is exactly what I told you. And, no, it’s not Meteor which is at fault here.
Again: The parameters given to an event handler always point to the object which invoked the event (and, of course, other stuff directly related to the event). If said object is not related to a <form /> why would you expect that the parameter includes the form’s values?
That’s pretty much standard in any language I’ve come across, be that Javascript, C#, Java, Ruby or whathaveyou.
There’s no magic in play here. It’s just a misunderstanding of how event handlers work - I strongly suggest you look them up a bit.
I hate to be a negative Nancy here, but the only issues I see are due to lack comprehending the technology you are using. I think some proper study is in order.
The way you’ve written it, your e.target points on the HTML element <a href...>. Blaze accepts a second parameter in the event handler allowing you to parse the DOM elements set up by your template. It would less error prone and more efficient than document.getElementById('title').value.