Last active
September 5, 2015 22:09
-
-
Save awei01/ebcc6ff6471878bfcfc6 to your computer and use it in GitHub Desktop.
Astronomy Validators: Am I missing something really simple?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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