|
@@ -16,6 +16,13 @@ Template.postSubmit.events({
|
|
|
title: $(e.target).find('[name=title]').val()
|
|
|
};
|
|
|
|
|
|
+ var errors = validatePost(post);
|
|
|
+ if (errors.title || errors.url) {
|
|
|
+ Session.set('postSubmitErrors', errors);
|
|
|
+ // We return to abort the helper, not for anyone using the result.
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
Meteor.call('postInsert', post, function (error, result) {
|
|
|
// Display the error to the user and abort.
|
|
|
if (error) {
|
|
@@ -29,3 +36,17 @@ Template.postSubmit.events({
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+Template.postSubmit.onCreated(function () {
|
|
|
+ Session.set('postSubmitErrors', {});
|
|
|
+});
|
|
|
+
|
|
|
+Template.postSubmit.helpers({
|
|
|
+ errorMessage: function (field) {
|
|
|
+ return Session.get('postSubmitErrors')[field];
|
|
|
+ },
|
|
|
+
|
|
|
+ errorClass: function (field) {
|
|
|
+ return Session.get('postSubmitErrors')[field] ? 'has-error' : '';
|
|
|
+ }
|
|
|
+});
|