I have a collection called Assesments and another collection called ChairAssesments, I have these defined separately now, but for later use I want to insert a value by default into ChairAssesments whenever I insert value in Assesments.
So I want to do something like
Assesments.after.insert(function (userId, doc) {
ChairAssesments.insert({ assesmentId: doc._id });
});
but this is not working
Assesment collection
Assesments = new Mongo.Collection('assesments');
ChairAssesments = new Mongo.Collection('chairassesments');
Assesments.after.insert(function (userId, doc) {
ChairAssesments.insert({ assesmentId: doc._id });
});
Assesments.before.insert(function (userId, doc) {
doc.createdAt = new Date();
doc.assesmentDate = new Date();
});
Assesments.attachSchema(new SimpleSchema({
name: {
type: String,
label: 'First Name',
autoform: {
'label-type': 'placeholder',
placeholder: 'First Name'
}
},
email: {
type: String,
label: 'Email',
autoform: {
'label-type': 'placeholder',
placeholder: 'Email'
}
},
category: {
type: String,
label: 'Category',
optional: true,
autoform: {
options: [
{value: 'General', label: 'General'},
{value: 'Reported', label: 'Reported'},
{value: 'Follow Up', label: 'Follow Up'}
],
type: 'select-radio'
}
},
assesmentDate: {
type: Date,
label: 'Assesment Date',
optional: true
},
location: {
type: String,
label: 'Location',
autoform: {
'label-type': 'placeholder',
placeholder: 'Location'
},
max: 200
},
chairAssesments:{
type: ChairAssesments
}
}
));
if (Meteor.isServer) {
Assesments.allow({
insert: function (doc) {
return true;
},
update: function (doc, fieldNames, modifier) {
return true;
},
remove: function (doc) {
return true;
}
});
}
ChairAssesment collection
ChairAssesment = new Mongo.Collection('chairassesment');
ChairAssesment.before.insert(function (userId, doc) {
doc.createdAt = new Date();
});
ChairAssesment.attachSchema(new SimpleSchema({
assesmentId: {
type: String
},
height: {
type: String,
label: 'Chair Height (Open hip angle)',
optional: true,
autoform: {
options: [
{value: 'Very Less', label: 'Very Less'},
{value: 'Medium', label: 'Medium'},
{value: 'Very High', label: 'Medium'}
],
type: 'select-radio'
}
},
backSupport: {
type: String,
label: 'Back Support',
optional: true,
autoform: {
options: [
{value: 'Very Less', label: 'Very Less'},
{value: 'Medium', label: 'Medium'},
{value: 'Very High', label: 'Medium'}
],
type: 'select-radio'
}
},
seatDepth: {
type: String,
label: 'Seat Depth',
optional: true,
autoform: {
options: [
{value: 'Very Less', label: 'Very Less'},
{value: 'Medium', label: 'Medium'},
{value: 'Very High', label: 'Medium'}
],
type: 'select-radio'
}
},
tiltLock: {
type: String,
label: 'Tilt Lock',
optional: true,
autoform: {
options: [
{value: 'Very Less', label: 'Very Less'},
{value: 'Medium', label: 'Medium'},
{value: 'Very High', label: 'Medium'}
],
type: 'select-radio'
}
},
armRests: {
type: String,
label: 'Arm Rests',
optional: true,
autoform: {
options: [
{value: 'Very Less', label: 'Very Less'},
{value: 'Medium', label: 'Medium'},
{value: 'Very High', label: 'Medium'}
],
type: 'select-radio'
}
},
fidgeting: {
type: String,
label: 'Fidgeting',
optional: true,
autoform: {
options: [
{value: 'Very Less', label: 'Very Less'},
{value: 'Medium', label: 'Medium'},
{value: 'Very High', label: 'Medium'}
],
type: 'select-radio'
}
},
standingUp: {
type: String,
label: 'Standing Up',
optional: true,
autoform: {
options: [
{value: 'Very Less', label: 'Very Less'},
{value: 'Medium', label: 'Medium'},
{value: 'Very High', label: 'Medium'}
],
type: 'select-radio'
}
}
}
));
if (Meteor.isServer) {
ChairAssesment.allow({
insert: function (doc) {
return true;
},
update: function (doc, fieldNames, modifier) {
return true;
},
remove: function (doc) {
return true;
}
});
}
Insert method of a collection takes object (JSON) as a first parameter. Read more about JavaScript objects here: http://www.codermania.com/javascript/lesson/1r/objects
Read more about insert method in Meteor docs: http://docs.meteor.com/#/full/insert
Your code should look like this:
Assesments.after.insert(function (userId, doc) {
ChairAssesments.insert({ assesmentId: doc._id });
});
Related
I have this schema:
AdsSchema = new SimpleSchema({
title: {
type: String,
label: "Title"
},
_cityId: {
type: String,
label: "City ID"
},
_categoryId: {
type: String,
label: "Category ID"
},
insertedDateTime: {
type: Date,
label: "Inserted Date Time",
autoValue: function() {
if (this.isInsert) {
return new Date();
} else if (this.isUpsert) {
return {$setOnInsert: new Date()};
} else {
this.unset(); // Prevent user from supplying their own value
}
}
},
insertedBy: {
type: String,
label: "Inserted By"
defalutValue: Meteor.user().username
},
price: {
type: Number,
label: "Price"
},
image: {
type: Object,
label: "Image",
optional: true
},
email: {
type: String,
label: "Email"
},
phoneNumber: {
type: String,
label: "Phone Number",
optional: true
},
desc: {
type: String,
label: "Description",
autoform: {
afFieldInput: {
type: "textarea",
rows: 10
}
}
},
quickOrNot: {
type: Boolean,
label: "Quick Or Not",
}
});
I use quickForm for insert to mongoDB, whit following code:
{{> quickForm schema="AdsSchema" collection="Ads" id="insBaseAds" type="insert"}}
and autoForm generate for me a form with all of schema's fields.
but I want only limit fields to show to user on autform, for example these fields:
title, price, image, email, phoneNumber, desc
and I fill some fields my self, for example these fields:
_cityId: "test",
_categoryId: "test",
insertBy: "test"
how can I use quickForm?
You can use afQuickfields
{{>afQuickFields fields="title, price, image, email, phoneNumber, desc"}}
else you can use type 'hidden' in schema
_cityId: {
type: String,
label: "City ID",
autoform:{
type:"hidden"
}
}
I have been working on extending the Meteor.users schema which work fine but after I create the first user in a Meteor.startup() and tried logging in I get a "User Not Found" error. Even though i can see the user in the mongo shell. Here is my schema:
Schemas.User = new SimpleSchema({
username: {
type: String,
optional: true
},
emails: {
type: Array,
optional: true
},
"emails.$": {
type: Object
},
"emails.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email
},
"emails.$.verified": {
type: Boolean
},
createdAt: {
type: Date,
optional: true
},
"firstName":{
type: String,
max: 50,
min:2
},
'middleName':{
type: String,
optional: true,
max: 50
},
"lastName":{
type: String,
max: 50,
min:2
},
"gender": {
type: String,
autoform: {
afFieldInput: {type: "select-radio-inline",},
options:
[
{label: "Male", value: "Male"},
{label: "Female", value: "Female"}
]
}
},
"branch": {
type: String,
optional: true,
autoform: {
type: "select",
options: function () {
return CompanyBranches.find().map(function (c) {
return {label: c.companyName+' - '+c.addressCity, value: c._id};
});
}
}
},
"active":{
type: String,
allowedValues: ["Yes","No"],
autoform: {
options: [
{label: "Yes", value: "Yes"},
{label: "No", value: "No"}
],
afFieldInput: {
type: "select-radio-inline"
}
}
},
services: {
type: Object,
optional: true,
blackbox: true
},
roles: {
type: [String],
optional: true,
autoform: {
options: [
{label: "Dashboard", value: "Dashboard"},
{label: "Branches", value: "Branches"},
{label: "User Profile", value: "User Profile"},
{label: "Case Managers", value: "Case Managers"},
{label: "Insurance Company", value: "Insurance Company"},
{label: "Tasks", value: "Tasks"},
{label: "Calendar", value: "Calendar"},
{label: "Contacts", value: "Contacts"},
{label: "Cases", value: "Cases"},
{label: "Requests", value: "Requests"},
{label: "Accounts", value: "Accounts"},
{label: "Reports", value: "Reports"},
{label: "Search", value: "Search"},
{label: "HR", value: "HR"}
],
afFieldInput: {
type: "select-checkbox-inline"
}
}
}
});
Meteor.users.attachSchema(Schemas.User);
This is my Meteor Startup function:
Meteor.startup(function () {
if ( Meteor.users.find().count() === 0 ) {
Accounts.createUser({
username: "leocrawf#gmail.com",
email:"leocrawf#gmail.com",
password: "leoten",
firstName: "Leocrawf",
lastName: "Stewart",
gender:"Male",
active: "Yes"
}, function (error) {
if (error) {
console.log("Cannot create user");
}
});
}
});
on the server i am doing this in the Accounts.onCreateUser():
Accounts.onCreateUser(function(options, user) {
user = options || {};
user.username = options.username;
user.firstName = options.firstName;
user.lastName = options.lastName;
user.active = options.active;
user.gender = options.gender;
// Returns the user object
return user;
});
When I query the mongo shell i get this:
meteor:PRIMARY> db.users.find().pretty()
{
"_id" : "pFurR8iDYWJcX9rus",
"username" : "leocrawf#gmail.com",
"firstName" : "Leocrawf",
"lastName" : "Stewart",
"gender" : "Male",
"active" : "Yes",
"services" : {
"resume" : {
"loginTokens" : [
{
"when" : ISODate("2016-02-05T23:13:38.364Z"),
"hashedToken" : "vs5xVlKL59yVTO/fbKbSnar38I8ILAruj2W1YecQ2Io="
}
]
}
}
}
It doesn't look like you're setting up the profile correctly when creating the user:
Instead of:
Accounts.createUser({
username: "leocrawf#gmail.com",
email:"leocrawf#gmail.com",
password: "leoten",
firstName: "Leocrawf",
lastName: "Stewart",
gender:"Male",
active: "Yes"
},
Try:
Accounts.createUser({
username: "leocrawf#gmail.com",
email: "leocrawf#gmail.com",
password: "leoten",
profile: {
firstName: "Leocrawf",
lastName: "Stewart",
gender: "Male",
active: "Yes"
}
},
Also I recommend active: true instead of active: "Yes" to use a boolean instead of a string. It doesn't look like you've defined active or gender in your schema either btw.
I have combo box with some values. When i click the combo listed down the data. but there not align with combo box and popup listed.
any help
/**
* This is the combo box with common values
*/
var combo_1 = Ext.extend(Ext.form.ComboBox, {
editable:true,
typeAhead: true,
mode: 'local',
triggerAction: 'all',
selectOnFocus:true,
anchor:'95%',
forceSelection: true,
tabIndex: 1,
labelStyle: 'width:110px'
});
/**
* This is the form panal
*/
var form_panal = new Ext.form.FormPanel({
id:'form_panal',
frame:true,
bodyStyle:'padding:10px 10px 10px 10px',
buttonAlign:'center',
items: [
combo_1,
combo_2,
combo_3,
combo_4
],
buttons: [ {
text: 'Save',
handler : function(){
}
},
{text: 'Cancel',
handler : function() {
}
}
]
});
enter image description here
Here is the sample code
Ext.application({
name : 'Fiddle',
launch : function() {
var combo_1 = Ext.create('Ext.form.field.ComboBox', {
editable:true,
typeAhead: true,
mode: 'local',
triggerAction: 'all',
selectOnFocus:true,
anchor:'95%',
forceSelection: true,
tabIndex: 1,
labelStyle: 'width:110px',
displayField: 'name',
valueField: 'name',
store: {
fields: [{
name: 'name'
}],
proxy: {
type: 'memory'
},
data: [{
name: 'Android'
},{
name: 'iOS'
}, {
name: 'Windows'
}]
}
});
var combo_2 = Ext.create('Ext.form.field.ComboBox', {
editable:true,
typeAhead: true,
mode: 'local',
triggerAction: 'all',
selectOnFocus:true,
anchor:'95%',
forceSelection: true,
tabIndex: 1,
labelStyle: 'width:110px',
displayField: 'name1',
valueField: 'name1',
store: {
fields: [{
name: 'name1'
}],
proxy: {
type: 'memory'
},
data: [{
name1: 'Blue Star'
},{
name1: 'LLoyd'
}, {
name1: 'Samsung'
}]
}
});
var combo_3 = Ext.create('Ext.form.field.ComboBox', {
editable:true,
typeAhead: true,
mode: 'local',
triggerAction: 'all',
selectOnFocus:true,
anchor:'95%',
forceSelection: true,
tabIndex: 1,
labelStyle: 'width:110px',
displayField: 'name2',
valueField: 'name2',
store: {
fields: [{
name: 'name2'
}],
proxy: {
type: 'memory'
},
data: [{
name2: 'Andhra pradesh'
},{
name2: 'Telangana'
}, {
name2: 'Karnataka'
}]
}
});
/**
* This is the form panal
*/
Ext.create('Ext.form.FormPanel',{
frame:true,
bodyStyle:'padding:10px 10px 10px 10px',
buttonAlign:'center',
items: [
combo_1,
combo_2,
combo_3
],
buttons: [ {
text: 'Save',
handler : function(){
}
},{
text: 'Cancel',
handler : function() {
}
}],
renderTo: document.body
});
}
});
I need to set slugs of my subcategories ,and i am using autovalue for this. I need to know the index of actual field for when i use arrays. There is a wild card for this?
Eg:
subcategories.$.subs.$.name
subcategories: {
type: [Object],
optional: true,
},
"subcategories.$.name": {
type: String,
optional: true,
},
"subcategories.$.slug": {
type: String,
optional: true,
autoform: {
omit: true
},
autoValue: function() {
if (this.field('subcategories.$.name').isSet) {
return s.slugify( (this.field('subcategories.$.name').value).toLowerCase() );
}
},
},
"subcategories.$.subs": {
type: [Object],
optional: true,
},
"subcategories.$.subs.$.name": {
type: String,
optional: true,
},
"subcategories.$.subs.$.slug": {
type: String,
optional: true,
autoform: {
omit: true
},
autoValue: function(i) {
if (this.field('subcategories.$.subs.$.name').isSet) {
return s.slugify( (this.field('subcategories.$.subs.$.name').value).toLowerCase() );
}
},
},
Thanks,
I got the expected result by changing the schema. Besides getting more organized, this.siblingField('name') works!
Code:
Categories = new Mongo.Collection('categories');
Schemas = {};
Schemas.Subs = new SimpleSchema({
"name": {
type: String,
optional: true,
},
"slug": {
type: String,
optional: true,
autoform: {
omit: true,
},
autoValue: function() {
if (this.siblingField('name').isSet) {
return s.slugify( (this.siblingField('name').value).toLowerCase() );
}
},
},
});
Schemas.Subcategories = new SimpleSchema({
"name": {
type: String,
optional: true,
},
"slug": {
type: String,
optional: true,
autoform: {
omit: true,
},
autoValue: function() {
if (this.siblingField('name').isSet) {
return s.slugify( (this.siblingField('name').value).toLowerCase() );
}
},
},
"subs": {
type: [Schemas.Subs],
optional: true,
},
});
Schemas.Categories = new SimpleSchema({
name: {
type: String,
},
slug:{
type: String,
unique: true,
index: 1,
autoform: {
omit: true
},
autoValue: function() {
if (this.field('name').isSet) {
return s.slugify( (this.field('name').value).toLowerCase() );
}
},
},
subcategories: {
type: [Schemas.Subcategories],
optional: true,
},
});
Categories.attachSchema(Schemas.Categories);
I am trying to make autoform like this.
What I want is Fields.$.min field to be seen only if fields.$.type ="Number". In the demo ( of aldeed:autoform) it is done for normal field but not for Array field. Tried several combinations to use afArrayField etc but no luck. Can this be done ?
Registers.attachSchema(new SimpleSchema({
config: {
type: Object
},
'config.name': {
type: String,
label: 'Register Name',
autoform: {
'label-type': 'floating',
placeholder: 'Register Name',
max: 200
}},
**fields: {
type: [Object]
}**,
'fields.$.name': {
type: String,
autoform: {
'label-type': 'placeholder',
placeholder: 'Field Name'
}
},
'fields.$.**min**': {
type: String,
autoform: {
'label-type': 'placeholder',
placeholder: 'Min Value'
}
},
'fields.$.type': {
type: String,
label: 'Label',
autoform: {
options: [
{value: 'String', label: 'String'},
{value: 'Number', label: 'Number'},
{value: 'Date', label: 'Date'},
{value: 'Password', label: 'Password'}
]
}
}
}));