1

I'm new to Meteor and programming, if this doesn't make sense or you need more info please let me know.

I'm loading a profile page of another user. So I have 2 userIds; this.userId and the other users Id. I want to use autoValue to save both userIds when an action is taken. I can't figure out how to set the other users id even though I can display it on the html page.

Path: schema.js

Schemas.class = new SimpleSchema({
    Title: {
        type: String,
        optional: true
    },
    teacherProfile: {
        type: String,
        optional: true,
        autoValue: function() {
            return this.userId
        },
        autoform: {
            type: "hidden"
        }
    },
    studentProfileId: {
        type: String,
        optional: true,
        type: String,
         autoform: {
         defaultValue: "studentProfileId",
         type: "hidden"
    }
    }
});

Path: profile.js

Template.teacherProfile.helpers({
studentProfile: ()=> { 
var id = FlowRouter.getParam('id');

return Meteor.users.findOne({_id: id}); 
}
});
bp123
  • 3,217
  • 8
  • 35
  • 74
  • 2
    I don't think you can set it using autovalue because SimpleSchema isn't looking at the DOM or a template data context afaik. You should set `otherUserProfileId` in your event handler or better yet, just set the hidden field value to it. – Michel Floyd Jan 30 '16 at 00:17
  • Thanks Michel. Can you show me how to set the hidden field to it, please. – bp123 Jan 30 '16 at 00:31
  • Use the `defaultValue` in your autoform layout See https://github.com/aldeed/meteor-autoform#affieldinput – Michel Floyd Jan 30 '16 at 00:43
  • Thanks @michel. When I use defaultValue I'm still unsure how I access the other users Id. I've tried to reference the id from {{id}} but that doesn't work. Any suggestions? – bp123 Jan 30 '16 at 02:56
  • How do you bring the other user into the template? – Michel Floyd Jan 30 '16 at 16:05
  • Sorry @MichelFloyd. I've included the helper above. I would like to set the studentProfile id as the defaultValue. Is that possible? – bp123 Jan 31 '16 at 01:52

1 Answers1

0

This is my solution it seems to work. Thanks to everyone that helped.

Path: schema.js

Schemas.class = new SimpleSchema({
    Title: {
        type: String,
        optional: true
    },
    teacherProfile: {
        type: String,
        optional: true,
        autoValue: function() {
            return this.userId
        },
        autoform: {
            type: "hidden"
        }
    },
    studentProfileId: {
        type: String,
        optional: true,
        autoform: {
            type: "hidden"
        }
    }
});

Path: profile.js

Template.profile.helpers({
    studentProfile: ()=> { 
        var id = FlowRouter.getParam('id');

        return Meteor.users.findOne({_id: id}); 
    },
    studentProfileId: () => {
        return FlowRouter.getParam('id');
    }
)};

Path: profile.html

<template name="profile">

    {{#autoForm collection="Jobs" id="Offer" type="insert"}}

        {{> afQuickField name='Title'}}               
        {{> afQuickField name='studentUserId' value=studentProfileId}}              

        <button type="submit" class="btn btn-primary">Insert</button>

    {{/autoForm}}

</template>
bp123
  • 3,217
  • 8
  • 35
  • 74