bp123
bp123

Reputation: 3427

Meteor: Set autoValue of field to anther profiles usersId

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}); 
}
});

Upvotes: 1

Views: 146

Answers (1)

bp123
bp123

Reputation: 3427

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>

Upvotes: 0

Related Questions