Erez
Erez

Reputation: 1953

Meteor, creating update form and filling fields

I have the following structure:

{
    id: 23423-dsfsdf-32423,
    name: Proj1,
    services: [
     {
        id:sdfs-24423-sdf,
        name:P1_Service1,
        products:[{},{},{}]
     },
     {
        id:sdfs-24jhh-sdf,
        name:P1_Service2,
        products:[{},{},{}]
     },
     {
        id:sdfs-2jnbn3-sdf,
        name:P1_Service3,
        products:[{},{},{}]
     }
    ]
},
{
    id: 23423-cxcvx-32423,
    name: Proj2,
    services: [
     {
        id:sdfs-xvxcv-sdf,
        name:P2_Service1,
        characteristics:[{},{},{}]
     },
     {
        id:sdfs-xvwqw-sdf,
        name:P2_Service2,
        characteristics:[{},{},{}]
     },
     {
        id:sdfs-erdfd-sdf,
        name:P2_Service3,
        characteristics:[{},{},{}]
     }
    ]
}

I have no problem creating a form this schema an insert form with quickForm. But I cant figure out (and tried to read every tutorial and instruction and nothing worked) how to create an update form with all fields filled and (need to expand and fill the services and the characteristics arrays also:

enter image description here

of course, as i said, in update i need the services and characteristics to expend to the right size with all the fields. But if i could understand how to fill the form fields i could understand myself how to expend the arrays...

i've tried:

         {{> quickForm collection="Projects" id="updateProjectForm" collection="Projects" type="method" class="update-project-form" doc=project }} 

with:

import SimpleSchema from 'simpl-schema';
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';

// Attaching the subscription to the template so we can reuse it
Template.ProjectSingle.onCreated(function(){
    var self = this;
    self.autorun(function(){
        var id = FlowRouter.getParam('id');
        self.subscribe('projectSingle', id);
    });
});

Template.ProjectSingle.helpers({
    project: ()=> {
        var id = FlowRouter.getParam('id');
        console.log(Projects.findOne({_id: id}));
        return Projects.findOne({_id: id});
    }
});

I can't even see the console.log() printing.

This solution at list didn't crash the meteor server... everything else i've tried crashed the server on many errors

Maybe i need to mention that i'm using partials so maybe there is a problem with the JS files but i don't think so as the onCreated method is being read.

10x.

EDIT:

I've removed the partial for the update template and it is now in the root Template with its own JS with the method:

projectDoc: ()=> {
    var id = FlowRouter.getParam('id');
    console.log("Update: " + Projects.findOne({_id: id}));
    return Projects.findOne({_id: id});
}

Now i can see this method is being called but for some reason it is being called twice. First with the correct data and then getting undefined so i've still not getting the fields showing anything but if i could find why it is being called twice i will solve the first level form (no services and so on)

Upvotes: 1

Views: 202

Answers (1)

Erez
Erez

Reputation: 1953

Solved it (Not sure this is the best way as i'm still having two calls to the method but this is working for now:

projectDoc: ()=> {
    var id = FlowRouter.getParam('id');
    if(Projects.findOne({_id: id}) != null){
        console.log(Projects.findOne({_id: id}));
        thisProject = Projects.findOne({_id: id});
        return Projects.findOne({_id: id});
    } else {
        return thisProject;
    }
}

Upvotes: 0

Related Questions