I have this helper, which returns update failed: MongoError: ‘$set’ is empty. You must specify a field like so: {$mod: {: …}}
'click #save': function(event){
template.autorun(function (c) {
var documentId = this._id;
var text = $('#summernote').code();
Posts.update({ _id: documentId}, {$set: { 'body': text}}, {tx: true});
console.log(text);
});
$('#summernote').destroy();
},
Summernote template: <div class=flow-text summernote" id="summernote">{{{body}}}</div>
template. No matter what I do, I’m unable to update the database. I had working at one point, but summernote wasn’t reactive, so none of the other clients will see changes, and required a refresh, which isn’t the meteor way… Any help?
Template.summernote.rendered = function() {
var template = this;
this.autorun(function() {
if (Template.currentData() && Posts.find().count())
$('#summernote').summernote({
maxHeight:800,
airmode: true,
onKeyup: function(e) {
var text = $("#summernote").code();
console.log(text);
},
onBlur: function(e) {
console.log('Editable area loses focus');
$('#summernote').destroy();
},
onEnter: function(e) {
console.log('Enter/Return key pressed');
template.autorun(function (c) {
var text = $('#summernote').code();
console.log(text);
Posts.update({_id: this._id}, { $set: {'body': text}});
console.log("onEnter:" + text);
});
},
onFocus: function(e) {
console.log('Editable area is focused');
var text = $('#summernote').code();
Posts.update({_id: this._id}, { $set: {'body': text}});
},
onImageUpload: function(files) {
Images.insert(files[0], function (err, fileObj) {
console.log("after insert:", fileObj._id);
template.autorun(function (c) {
fileObj = Images.findOne(fileObj._id);
var url = fileObj.url();
if (url) {
$("#summernote").summernote("insertImage", fileObj.url(), this.title);
//editor.insertImage($editable, url);
c.stop();
}
var $dom = $("<img>").attr('src',url);
$("#summernote").summernote('insertNode', $dom[0]);
}, {tx: true});
});
}
});
});
}