0
votes

I am having problems with Collection2 and autoform. Here is my collection

Customers = new Mongo.Collection("customers");

Customers.allow({
	insert: function(userId, doc) {		
		return !!userId;
	}
});

CustomerSchema = new SimpleSchema({
	name: {
		type: String,
		label: "Name"
	},
	address: {
		type: String,
		label: "Address"
	},
	amount: {
		type: Number,
		label: "Amount"
	},
	bvn: {
		type: String,
		label: "BVN"
	},
	type: {
		type: String,
		label: "Sale Type"
	},
	saleDate: {
		type: Date,
		label: "Transaction Date",
		autoValue: function() {
			return new Date()
		},
		autoform: {
			type: "hidden"
		}
	},
	passport: {
		type: String,
		label: "Passport Number"
	},
	source: {
		type: String,
		label: "Source"
	},
	tickets: {
		type: Boolean,
		label: "Tickets"
	},
	visa: {
		type: Boolean,
		label: "Visa"
	},
	invoice: {
		type: Boolean,
		label: "Invoice"
	},
	nextSaleDate: {
		type: Date,
		label: "Next Sale Date",
		autoValue: function () {
			var thisDate = new Date();
			var dd = thisDate.getDate();
			var mm = thisDate.getMonth() + 3;
			var y = thisDate.getFullYear();

			var nextDate = dd + '/'+ mm + '/'+ y;
			return nextDate;
		},
		autoform: {
		type: "hidden"
		}
	},
	author: {
		type: String,
		label: "Author",
		autoValue: function () {
			return this.userId
		},
		autoform: {
		type: "hidden"
		}
	}	

});
Customers.attachSchema(CustomerSchema);

I have published and subscribed to the collections in separate publish and subscribe javascript files with methods Meteor.publish('customers', function() { return Customers.find({author: this.userId}); }); and Meteor.subscribe("customers"); respectively. Here is the html code for insert

<template name="NewCustomer">
	<div class="new-customer">
		{{>quickForm collection="Customers" id="insertCustomerForm" type="insert" class="new-customer-form"}}
	</div>
</template>

But when i bootup the server and add a new customer, it doesn't work. Can anyone help me out? Thank you

1
Everything looks right to me. Where is the code that you are using to display the customer once it is inserted? - Nate
I am using meteortoys to check whether the customer is added, and I used the mongodb cli to check whether its added to the collection. - Hayatu Mohammed Abubakar
It looks right to me too. You don't have any error message? - jkoestinger
none. I have no error messages whatsoever. I even deployed it on meteor, its still not saving - Hayatu Mohammed Abubakar

1 Answers

0
votes

I sorted it out. This field in the collection

nextSaleDate: {
		type: Date,
		label: "Next Sale Date",
		autoValue: function () {
			var thisDate = new Date();
			var dd = thisDate.getDate();
			var mm = thisDate.getMonth() + 3;
			var y = thisDate.getFullYear();

			var nextDate = dd + '/'+ mm + '/'+ y;
			return nextDate;
		},
		autoform: {
		type: "hidden"
		}
	},

is the one causing the issue. Thank you all for your input