Hello there !
I’m actually trying to edit a record of a specific collection in a project. I’m using aldeed:autoform for this and i really want to go through it.
Perhaps, the update doesn’t work (Nothing happen on submit).
Here is my code :
collection.js
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';
Pipelines = new Mongo.Collection('pipelines');
Pipelines.allow({
insert: function(userId, doc) {
return !!userId;
},
update: function (userId, doc) {
return !!userId;
}
});
PipelinesSchema = new SimpleSchema ({
name: {
type: String,
label: "Name"
},
desc: {
type: String,
label: "Description"
}
});
Meteor.methods({
crmDeletePipeline: function(id) {
Pipelines.remove(id)
},
});
Pipelines.attachSchema(PipelinesSchema);
crm_single_pipeline.js
Template.crmSinglePipeline.onCreated(function() {
var self = this;
this.editMode = new ReactiveVar(false);
self.autorun(function() {
var id = FlowRouter.getParam('_id');
self.subscribe('Pipelines', id);
});
});
Template.crmSinglePipeline.helpers({
pipeline: () => {
var id = FlowRouter.getParam('_id');
return Pipelines.findOne({_id: id});
},
updatePipelineId: function() {
return FlowRouter.getParam('_id');
},
editMode: function () {
return Template.instance().editMode.get();
},
});
Template.crmSinglePipeline.events({
'click .btn-danger': function (){
var id = FlowRouter.getParam('_id');
Meteor.call('crmDeletePipeline', id);
FlowRouter.go('crm');
swal("Deleted", "This record was properly deleted !", "success");
},
'click .btn-warning': function (event, template){
template.editMode.set(!template.editMode.get());
console.log(template.editMode.get());
},
});
crm_single_pipeline.html
<template name="crmSinglePipeline">
<div class="row col-md-12">
<div class="col-md-8">
<h1>Pipeline</h1>
</div>
<div class="col-md-4">
<div class="pull-right">
<button type="button" class="btn btn-danger">Delete</button>
<button type="button" class="btn btn-warning">Edit</button>
</div>
</div>
</div>
<hr>
{{#if editMode}}
{{> quickForm collection="Pipelines" doc=this id="updatePipelineId" type="update" class="new-pipelines-form" autosave=true}}
{{else}}
<div class="row col-md-12">
<div class="col-md-6">
<h3>{{pipeline.name}}</h3>
</div>
</div>
{{/if}}
</template>
I actually can’t figure out what’s wrong in it. Also, i think i don’t really get what the doc=this use to find out which document should be updated.
Thanks a lot for your help in advance
Brawcks