Do not disable submit button if comment is empty in mobile view

Fixes #5485
This commit is contained in:
Manuel Vögele 2015-11-12 02:44:10 +01:00
parent 7fca5cf93a
commit 1680c0c924
3 changed files with 58 additions and 5 deletions

View file

@ -30,13 +30,24 @@
self.scrollToOffset(commentContainer); self.scrollToOffset(commentContainer);
}); });
$(".stream").on("submit", ".new_comment", function(evt) { $(".stream").on("submit", ".new_comment", this.submitComment);
},
submitComment: function(evt) {
evt.preventDefault(); evt.preventDefault();
var form = $(this); var form = $(this);
var commentBox = form.find(".comment_box");
var commentText = $.trim(commentBox.val());
if (commentText) {
$.post(form.attr("action")+"?format=mobile", form.serialize(), function(data) { $.post(form.attr("action")+"?format=mobile", form.serialize(), function(data) {
self.updateStream(form, data); Diaspora.Mobile.Comments.updateStream(form, data);
}, "html"); }, "html");
}); return true;
}
else {
commentBox.focus();
return false;
}
}, },
toggleComments: function(toggleReactionsLink) { toggleComments: function(toggleReactionsLink) {

View file

@ -0,0 +1,20 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require "spec_helper"
describe CommentsController, type: :controller do
describe "#comments" do
before do
sign_in :user, alice
end
context "jasmine fixtures" do
it "generates a jasmine fixture with the mobile comment box", fixture: true do
get :new, format: :mobile, post_id: 1
save_fixture(html_for("div"), "comments_mobile_commentbox")
end
end
end
end

View file

@ -116,4 +116,26 @@ describe("Diaspora.Mobile.Comments", function(){
expect(jQuery.ajax).not.toHaveBeenCalled(); expect(jQuery.ajax).not.toHaveBeenCalled();
}); });
}); });
describe("createComment", function () {
beforeEach(function() {
spec.loadFixture("aspects_index_mobile_post_with_comments");
var commentBoxHtml = spec.fixtureHtml("comments_mobile_commentbox");
var link = $(".stream .comment-action").first();
Diaspora.Mobile.Comments.showCommentBox(link);
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: "text/html",
responseText: commentBoxHtml
});
$(".stream .new_comment").submit(Diaspora.Mobile.Comments.submitComment);
});
it("doesn't submit an empty comment", function() {
var form = $(".stream .new_comment").first();
spyOn(jQuery, "ajax");
form.submit();
expect(jQuery.ajax).not.toHaveBeenCalled();
});
});
}); });