Skip to content

Instantly share code, notes, and snippets.

@awei01
Last active September 5, 2015 22:09
Show Gist options
  • Save awei01/ebcc6ff6471878bfcfc6 to your computer and use it in GitHub Desktop.
Save awei01/ebcc6ff6471878bfcfc6 to your computer and use it in GitHub Desktop.
Astronomy Validators: Am I missing something really simple?
Model = Astro.createClass({
name: "Model",
fields: {
height: "number",
}
});
Model.addValidator('height', Validators.number());
if (Meteor.isClient) {
Template.hello.events({
"submit form": function(event) {
event.preventDefault();
var data = {
height: "not a number",
ignored: "This shouldn't show",
};
var instance = new Model(data);
console.log(instance.validateAll()); // expected this to be false
console.log(instance.getValidationErrors()); // expected to get an error object
// same situation on server
Meteor.call('validateData', data, function(err, result) {
console.log(result.valid);
console.log(result.errors);
});
}
});
}
if (Meteor.isServer) {
Meteor.methods({
validateData: function(data) {
var instance = new Model(data);
return { valid: instance.validateAll(), errors: instance.getValidationErrors() };
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment