var HootForm = FormView.extend({ el: "#hootform", events: {}, action: "/api/thread/1/comment", initialize: function (opt) { this.__super__.initialize.call(this); this.$comment = this.$("[name=comment]"); }, show: function () { this.$el.show(); }, hide: function () { this.$el.hide(); }, toggle: function (state) { if (state) { this.show(); } else { this.hide(); } }, load: function (comments) { if (!comments || (!comments.length && !this.options.required)) { this.$el.hide(); return; } comments.forEach(this.appendComment.bind(this)); }, validate: function () { var errors = []; var comment = $("[name=comment]").val(); if (!comment || !comment.length) { errors.push("Please enter a comment."); } return errors.length ? errors : null; }, success: function (data) { this.parent.onComment(data.comment); this.$("[name=comment]").val(""); }, });