Reputation: 3869
I'm trying to get minimongoid to work with meteorjs but I get an error statement:
Error: AutoForm: collection attribute for form with id "insertBuildingForm" is not a Meteor.Collection instance
Does that mean that a minimongoid collection is not considered as a Meteor collection and that I cannot have it to play with autoform? Or am I doing something wrong?
If minimongoid and autoform are not compatible, what is the best way to manage validation with minimongoid? I mean automatically... ;-)
Thx.
Upvotes: 0
Views: 264
Reputation: 6733
I got it working, using this:
EDIT: With the release of collection2 2.0, the API has changed and you MUST use attachSchema ie
class @Book extends Minimongoid
@_collection: new Meteor.Collection('books')
Book._collection.attachSchema new SimpleSchema({
name:
type: String
label: "Name"
max: 200
author:
type: String
label: "Author"
publishedDate:
type: Date
label: "Publication Date"
price:
type: Number
label: "Price"
min: 0
})
Then in the html template
{{> quickForm collection="Book._collection" id="insertBookForm" type="insert"}}
Notice the collection should be Book._collection
Upvotes: 1
Reputation: 75945
Yes this means the minimongoid collection is not compatible, unless it is an extension of Meteor.Collection.
The line that does this is here: https://github.com/aldeed/meteor-autoform/blob/e77832d40f8eec2ddb92d97f481bf86fb712d9ca/utility.js#L261-L263
It's hard to say how to do it with minimongoid, since it is not a core package. It does support validation itself though.
validate: ->
unless @name and @name.length > 3
@error('name', 'Recipe name is required and should be longer than 3 letters.')
The way it supports validation is via the Collection.insert rules (I think?). So at the point where you try and insert the document you will get this error, similar to how the Access Denied error works when you remove the insecure
package.
There is also client side validation, you would have to check the errors
attribute via e.g via Recipe.errors.length
Upvotes: 0