var EditCommentForm = FormView.extend({ el: "#comment_form", events: { "focus textarea": 'focus', "keydown textarea": 'keydown', }, action: "", method: 'put', initialize: function(){ this.__super__.initialize.call(this) this.template = this.$(".template").html() this.$comment = this.$("[name=comment]") }, load: function(id){ this.action = "/api/comment/" + id $.get(this.action, function(data){ this.$comment.val(data.comment.comment).focus() console.log(this.$comment) setCaretToPos(this.$comment.get(0), 0, 0) $("body").removeClass("loading") }.bind(this)) }, focus: function(){ this.$el.addClass('focused') }, keydown: function(e){ if ((e.ctrlKey || e.metaKey || e.altKey) && e.keyCode == 83) { // "s" key e.preventDefault() e.stopPropagation() this.save() } }, 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){ window.location.href = "/details/" + data.comment.thread } })