var SignUpModal = ModalView.extend({ el: ".mediaDrawer.signup", action: "/auth/signup", events: { "submit form": "submit", }, initialize: function(){ this.$form = this.$("form") this.$errors = this.$(".errors") this.$errorList = this.$(".errorList") }, reset: function(){ this.$("input").not("[type='submit']").not("[type='hidden']").val("") }, load: function(){ this.reset() this.show() }, validate: function(){ var errors = [] var username = this.$("#usernameInput").val() var email = this.$("#emailInput").val() var pw1 = this.$("#passwordInput1").val() var pw2 = this.$("#passwordInput2").val() if (! username.length) { errors.push("Please enter a username"); } if (! pw1.length) { errors.push("Please enter a password"); } if (! email.length) { errors.push("Please enter an email address"); } else if (email.indexOf("@") === -1) { errors.push("Please enter a valid email address"); } if (pw1 !== pw2) { errors.push("Passwords don't match"); } if (errors.length) { this.$errors.show(); for (var i in errors) { this.$errorList.append('