I’ve got this template in my Meteor app to insert a Document in a MongoDB Collection:
Add a Job/Location
Log In
Designation for Job/Location
Save Job/Location
Here is the client-side code:
Template.addJobLoc.events({
'click #btnSaveJobLoc': function(event, template) {
var username = Session.get("username");
var jobloc = template.find('#textJobLoc').value;
Meteor.call('insertJobLocation', username, jobloc, function(err) {
if (err) {
Session.set("lastErrMsg", err.message);
} else {
alert(jobloc + ' inserted');
$('#textJobLoc').val("");
$('#textJobLoc').focus();
} // else
}); // Meteor call
} // click event
});
…and the server-side code:
Meteor.methods({
'insertJobLocation': function(username, jobLoc) {
JobLocations.insert({
jl_username: username,
jl_jobloc: jobLoc,
jl_created_by: this.userId
});
},
. . .
The DB code is working - the Document is inserted into the Collection - but then my “addJobLoc” Template disappears, and the default/starting point Template reappears. I don’t want that - I want to be able to enter multiple Job Locations. That’s why I switched from using the form tag and an input type=“submit” element - so that the form wouldn’t submit and invalidate the page.
So why is it doing that, and how can I prevent it?