javascript - Meteor Single collection Field Editable Content -
i attempting make element in meteor template editable via update function. data changes when inserted server side code in fixture.js
code. have no luck updating via editable form template.name.events({});
code and, creating collection, publishing , subscribing it. last piece of code fixture.js
file. in regard can insert collection , update it, have no luck edit financialsedit
template. router.js
file included contains parts regarding financials
template. if needed post more.
basically can't update collection value update function using $set
, passing key value pair.
update: added permissions.js file in lib directory show ownsdocument
returns.
here code.
client directory
client/editable/edit_financial.js
template.financialsedit.events({ 'submit .financialsedit': function(e) { e.preventdefault(); var currentfinanceid = this._id; var financialsproperties = { issuedoutstanding: $('#issuedoutstanding').val() } financials.update(currentfinanceid, {$set: financialsproperties}, function(error) { if (error) { alert(error.reason); } else { console.log(financialsproperties); // router.go('financials'); router.go('financials'); } }); } });
client/editable/financials_helpers.js
template.financials.helpers({ financials: function() { return financials.find(); }, ownfinancial: function() { return this.userid === meteor.userid(); } });
client/editable/financials
<template name="financials"> <div id="finance"> {{#each financials}} <h2>issued outstand : {{issuedoutstanding}}</h2> {{/each}} </div> </template>
client/editable/financials_edit.html
<template name="financialsedit"> <form class="main form financialsedit"> <input id="issuedoutstanding" type="number" value="{{issuedoutstanding}}" placeholder="{{issuedoutstanding}}" class="form-control"> <input type="submit" value="submit" class="submit"/> </form> </template>
lib directory lib/router.js
router.route('/financials', function () { this.render('financials'); }); router.route('/financialsedit', {name: 'financialsedit'});
lib/collections/financials.js
financials = new mongo.collection('financials'); financials.allow({ update: function(userid, financial) { return ownsdocument(userid, financial); }, remove: function(userid, financial) { return ownsdocument(userid, financial); }, }); financials.deny({ update: function(userid, financial, fieldnames) { // may edit following 2 fields: return (_.without(fieldnames, 'issuedoutstanding').length > 0); } });
lib/permissions.js
// check userid specified owns documents ownsdocument = function(userid, doc) { return doc && doc.userid === userid; }
server/publications.js
meteor.publish('financials', function() { return financials.find(); });
server/fixture.js
if (financials.find().count() === 0) { financials.insert({ issuedoutstanding: '43253242' }); }
Comments
Post a Comment