'click #add_addr_save': function (e) {
e.preventDefault();
var $form = $('#add_address');
var addr = {};
addr.departement = $form.find('#add_departement').val();
addr.city = toTitleCase($form.find('#add_city').val());
addr.addr = $form.find('#add_addr').val();
addr.addr_comp = $form.find('#add_addr_comp').val();
addr.contact = $form.find('#add_addr_contact').val();
addr.note = $form.find('#add_addr_note').val();
Meteor.call('checkAddr', addr, function (err) {
if (!err) {
Meteor.subscribe('addresses', Meteor.userId());
} else
console.log(err);
});
});
Meteor.publish('addresses', function(opt) { var fields = {};
if (opt != this.userId) {
fields = {fields: {city: true, departement: true} };
}
var user = Meteor.users.findOne({$or: [{_id: opt}, {username: opt}]});
if (user) {
var addresses = user.addresses;
return Address.find({_id: {$in : addresses}}, fields);
}
return Address.find({_id: -1});
});<p class="text-center">
<button class="btn btn-info" id="add_addr_save">Add</button>
</p>
Can you please explain the logic of what you are trying to do? Why do you need to call subscribe when saving a new address? (subscribe is to load data, right?)Having some elements of a page refreshed when calling subscribe is very common: if a template HTML uses a helper that returns a cursor, then any change in the subscribe that changes the cursor will trigger a refresh.
--
You received this message because you are subscribed to the Google Groups "meteor-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to meteor-talk...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/meteor-talk/53540c87-3ff5-448b-b342-9dc450d0efa4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/meteor-talk/CAB6spNzGuO6_kBAUhSvqP2OP%3D-w-AXLr4FWtZkYDrxq9a0fCRA%40mail.gmail.com.
<template name="addresses"> <h3>Registered addresses</h3>
<div class="panel-body"> <div class="col-sm-12"> {{#each getAddr}} <div class="col-sm-6"> <input type="hidden" class="addressIndex" value="{{_id}}"/> <address> <p><strong>{{getCity city}}</strong> <small>— {{departement}}</small> </p> <p>{{addr}}{{#if addr_comp}} — {{addr_comp}}{{/if}}</p> {{#if contact}}<p><abbr tile="Contact">Tel</abbr>: {{contact}}</p>{{/if}} {{#if note}} <p> <small>{{note}}</small> </p>{{/if}} </address> </div> {{/each}} </div> <div class="col-sm-12"> <legend>Add new</legend> {{> addAddress}} </div> </div></template>Template.addresses.helpers({ getAddr: function () { var user = Meteor.user(); var addr = []; if (user) { addr = user.addresses; ret = []; addr.forEach(function (elem, index, arr) { var address = Address.findOne(elem); if (address) { Meteor.subscribe('ville', address.ville); ret.push(address); } }); return ret; } }});