0

Just getting started with Parse.com and following their JavaScript ToDo app tutorial and having some issues.

Basically it will work perfectly and post to the Parse database when I just have the Username and Password but if I try to add any additional fields like email or phone, it won't send it to the database. I have already defined both email and phone fields in my Parse database.

Any help would be appreciated. Thanks!

My html for my form:

<script type="text/template" id="login-template">
  <header id="header"></header>
   <form class="signup-form">
      <h2>Sign Up</h2>
      <div class="error" style="display:none"></div>
      <input type="text" id="signup-username" placeholder="Username" />
      <input type="password" id="signup-password" placeholder="Create a Password" />
      <input type="email" id="signup-email" placeholder="Email" />
       <input type="text" id="signup-phone" placeholder="Phone" />
      <button>Sign Up</button>
    </form>
  </div>
</script>

My JS:

var LogInView = Parse.View.extend({
events: {
  "submit form.signup-form": "signUp"
},

el: ".content",

initialize: function() {
  _.bindAll(this, "signUp");
  this.render();
},

signUp: function(e) {
  var self = this;
  var username = this.$("#signup-username").val();
  var password = this.$("#signup-password").val();
  var email = this.$("#signup-email").val();
  var phone = this.$("#signup-phone").val();

  Parse.User.signUp(username, password, email, phone, { ACL: new Parse.ACL() }, {
    success: function(user) {
      new ManageTodosView();
      self.undelegateEvents();
      delete self;
    },

    error: function(user, error) {
      self.$(".signup-form .error").html(error.message).show();
      self.$(".signup-form button").removeAttr("disabled");
    }
  });

  this.$(".signup-form button").attr("disabled", "disabled");

  return false;
},

render: function() {
  this.$el.html(_.template($("#login-template").html()));
  this.delegateEvents();
}
});

2 Answers 2

1

You should use the following syntax, like specified in the javascript docs (https://parse.com/docs/js_guide):

var user = new Parse.User();
user.set("username",username);
user.set("password",password);
user.set("email",email);
user.set("phone",phone);

user.signUp(null,{
    success:function(user){...},
    error:function(user,error){...}
});

You can add any fields you want with the set method.

Sign up to request clarification or add additional context in comments.

2 Comments

How do I integrate that with my form though?
I just copied my snippet and replaced your Parse.User.signUp line. jsfiddle.net/31x9un9m
0

I had to change <!--<button>Submit</button>--> to <!--<input type="submit"></input>--> to get this to work but then it did. Thanks.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.