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

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -