You can indicate in result of that meteor.call state when nothing was updated and act according it in callback . Callback is optional meteor.call parameter.
Hi @shock, thanks for that hint but as I said, there are also collection hooks / methods as well we are using to validate the data before storing them.
I mean, the template is bound to those fields like
<input value="{{foo}}" ...
In that case there should be / is already? an easy way to make sure that those fields have to be checked after change.
Maybe something like: e.refresh or Blaze.invalidateElement(e)
there is no technical reason, currently we are doing it like that:
Template.Foo.events({
'change .value-bar': function(e) {
var input_value = e.target.value;
// update document -> will self check for valid values
if (this.update({ bar: input_value })) {
// on success we have to re-read last value from collection
var new_bar = Col.findOne('_id:' + this._id).bar;
// make sure to have that value also in templates field
e.target.value = new_value;
} else {
// reset value in any case with last template data value
e.target.value = this.bar;
}
}
}
But as you can see, if this has to be done for a number of fields and templates, it is a lot of code copy and paste.
For my opinion, this should work like
Template.Foo.events({
'change .value-bar': function(e) {
var input_value = e.target.value;
// update document -> will self check for valid values
this.update({ bar: input_value });
}
}
That means, whatever the collection processing will do, it should be possible to signal the invalidation of collections data.
Let’s do it in a collections transform
Col = new Meteor.Collection("col", {
transform: function (doc) {
doc.update = function (values) {
if (values ... whatever check) {
.....
}
// Now I know, that this document should be re-read by collection
// I mark it as invalid
METEOR.INVALIDATE_DOCUMENT(this);
return true;
}
}
});
Maybe that already exist ??? I don’t know, otherwise I would like to have something available like that.