javascript - How do you set the Meteor.userId() for use within autoform/simple-schema? -


say want display list user's shopping items once logged in. i'm using autoform , simple-schema generate form elements. when user logs in first time blank shopping list form displayed. when submitting form shopping list saved in db.

what want know how can save data each user.

normally this:

      shoppinglist.insert({         name: item_name,         price: 0,         createdby: meteor.userid()       }); 

how acheive using autoform , simple-schema? possible this:

schema.shoppinglist = new simpleschema({ item: {     type: string,     regex: /^[a-za-z-]{2,25}$/ }, price: {     type: number,     regex: /^[0-9]{2,25}$/ }, createdby: {     type: string,     value: meteor.userid() } }); 

thanks again :)

if using collection2 use autovalue:

schema.shoppinglist = new simpleschema({ item: {     type: string,     regex: /^[a-za-z-]{2,25}$/ }, price: {     type: number,     regex: /^[0-9]{2,25}$/ }, createdby: {     type: string,     autovalue:function(){ return this.userid } } }); 

read more : https://github.com/aldeed/meteor-collection2/


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

Error while updating a record in APEX screen -

c++ - In an add-in in Excel, written in C(++), how does one get the name of the function which called into the addin? -