disable form inputs on post and comment submit

This commit is contained in:
Sacha Greif 2015-09-23 11:36:19 +09:00
parent 0254d13a4b
commit b192c2a74b
2 changed files with 8 additions and 2 deletions

View file

@ -16,6 +16,8 @@ AutoForm.hooks({
var comment = doc; var comment = doc;
this.template.$('button[type=submit]').addClass('loading'); this.template.$('button[type=submit]').addClass('loading');
this.template.$('input, textarea').not(":disabled").addClass("disabled").prop("disabled", true);
var parent = this.formAttributes.parentContext; var parent = this.formAttributes.parentContext;
if (!!parent.comment) { // child comment if (!!parent.comment) { // child comment
@ -51,6 +53,8 @@ AutoForm.hooks({
onSuccess: function(operation, comment) { onSuccess: function(operation, comment) {
this.template.$('button[type=submit]').removeClass('loading'); this.template.$('button[type=submit]').removeClass('loading');
this.template.$('.disabled').removeClass("disabled").prop("disabled", false);
Events.track("new comment", {'commentId': comment._id}); Events.track("new comment", {'commentId': comment._id});
FlowRouter.go('postPage', {_id: comment.postId}); FlowRouter.go('postPage', {_id: comment.postId});
if (comment.status === Posts.config.STATUS_PENDING) { if (comment.status === Posts.config.STATUS_PENDING) {
@ -60,6 +64,8 @@ AutoForm.hooks({
onError: function(operation, error) { onError: function(operation, error) {
this.template.$('button[type=submit]').removeClass('loading'); this.template.$('button[type=submit]').removeClass('loading');
this.template.$('.disabled').removeClass("disabled").prop("disabled", false);
Messages.flash(error.message.split('|')[0], 'error'); // workaround because error.details returns undefined Messages.flash(error.message.split('|')[0], 'error'); // workaround because error.details returns undefined
Messages.clearSeen(); Messages.clearSeen();
} }

View file

@ -17,7 +17,7 @@ AutoForm.hooks({
var post = doc; var post = doc;
this.template.$('button[type=submit]').addClass('loading'); this.template.$('button[type=submit]').addClass('loading');
this.template.$('input').not(":disabled").addClass("disabled").prop("disabled", true); this.template.$('input, textarea').not(":disabled").addClass("disabled").prop("disabled", true);
// ------------------------------ Checks ------------------------------ // // ------------------------------ Checks ------------------------------ //
@ -46,7 +46,7 @@ AutoForm.hooks({
onError: function(operation, error) { onError: function(operation, error) {
this.template.$('button[type=submit]').removeClass('loading'); this.template.$('button[type=submit]').removeClass('loading');
this.template.$('input.disabled').removeClass("disabled").prop("disabled", false); this.template.$('.disabled').removeClass("disabled").prop("disabled", false);
Messages.flash(error.message.split('|')[0], 'error'); // workaround because error.details returns undefined Messages.flash(error.message.split('|')[0], 'error'); // workaround because error.details returns undefined
Messages.clearSeen(); Messages.clearSeen();