I want to store the URLs from the user to the database. So far I have created Session
variables in the client side and store the values there and I pass them to the server using Meteor methods.
These are the methods that do this
screenshotsURLS: function (sshots) {
check(sshots, [String]);
// Products.update({},{$set:{screenShots:sshots}});
scs = sshots.slice();
console.log(scs);
},
previewImageUrl: function (url) {
check(url, String);
pi = url;
console.log(pi);
},
sourceCodeUrl: function (url) {
check(url, String);
zip = url;
console.log(zip);
}
These three variables "scs, pi, zip" are initialized like this:
var zip;
var pi;
var scs = [];
My code works fine and i manage to store the values of the variables inside my collection, the problem is when i open the website from two browsers and call the functions one and the other. the variables above will have the values of the last one who called the function.
they are stores in the collection like this:
submitPost: function (app) {
// Console.log('new App:', app);
check(app, {
title: String,
description: String,
category: String,
price: Number
});
var knownId = Products.insert(app);
Products.update({ _id: knownId }, { $set:{previewImage: pi, sourceCode: zip }});
}
and for the scs am returning the value using the autoValue
screenShots: {
type: [String],
autoValue: function() {
return scs;
}
}
for the submitPost, it is called from the quickForm in the html file this way
{{> quickForm collection="Products" id="submitPostForm"
type="method" meteormethod="submitPost" omitFields="createdAt, previewImage, screenShots, sourceCode, userID"}}
once the user clicks submit button, the submitPost will be triggered.
The AutoForm.hooks implementation
AutoForm.hooks({
submitPostForm: { //<--- this is the id of your form
before: { //<-- before submit
methodName: function (doc) { //<-- get the doc to be submitted
//HERE YOU CAN MANIPULATE THE FORM FIELDS BEFORE SUBMIT
var previewImage = Session.get("previewImageURL")
if (previewImage) {
doc.previewImage = previewImage;
}
var sourceCode = Session.get("sourceCodeURL");
if (sourceCode) {
doc.sourceCode = sourceCode;
}
var screenshots = Session.get("screenshots");
if (screenshots) {
doc.screenShots = screenshots;
}
return doc;
}
},
onSuccess: function (formType, result) {
},
onError: function (formType, error) {
}
}
});
I believe my AutoForm.hooks doesn't work for some reason because when i try to console.log("previewImage") nothing happens!
How do i separate the variables "scs, pi, zip" for every user so that they don't contradict?