Here is my method for adding elements to a list, which contains links to articles, using an input field:
Template.addForm.events({
'submit form': function(event){
event.preventDefault();
var title = event.target.text.value;
MongoValues.insert({
title: title,
slug: title.toLowerCase()
}, function(error, result) { if(error) console.warn(error); });
event.target.text.value = "";
}
});
I am now working on preventing duplicate entries. If a user wants to add a title that already exists, I want to redirect them to the existing element (route to article/_id
) instead of adding the title to the list again.