Closed laurentpayot closed 8 years ago
Hi, you have an error in you code. You've defined the tags.$.tag
validator as the field instead validator. Nested validators have to be defined under the validators
property in the schema.
In fact the way you define nested fields and validators will change in the next release which is going to be published soon.
Thanks for your quick answer. I'm closing the issue, waiting for the next release then... :hourglass:
And to make it clear for all I will post the correct code:
var V = Validators;
Foos = new Mongo.Collection('foos');
Foo = Astro.Class({
name: 'Foo',
collection: Foos,
fields: {
'tags': {
type: 'array',
default: [],
index: true,
validators: [V.required(), V.array(), V.maxLength(100)]
},
validators: {
'tags.$': [V.object()],
'tags.$.tag': [V.required(), V.string(), V.minLength(2), V.maxLength(20)]
}
});
:+1:
I'm trying to set validators for an array of tags but it doesn't seem to work. Am I doing it the right way?
(I'm quickly pasting my CoffeeScript code, hope you don't mind...)
When I validate it in Meteor shell I get the following: