0

I have posted my code here.

On click of add button,i am trying to create new record in model but here it is adding blank record.

    savecontact: function(){
    App.Person.createRecord({   
          fname: this.get('firstName'),
          lname: this.get('lastName'),
          contactype: 1
        });
        this.get('store').commit(); 
},

Can anyone tell me why createRecord is adding blank record?

2 Answers 2

2

There were a few problems. First, all three of the propertyNames were incorrect. Should be firstName, lastName and contacttype instead of fname, lname and contactype. Second, this.get('firstName') should be this.get('currentContact.firstName') and third you need to initialize currentContact to an empty object when showing the modal. With those changes, the create new record modal is no longer adding blank record.

showmodal: function(){
    this.set('currentContact', {});
    $('#modal').modal();
},
savecontact: function(){
    App.Person.createRecord({
      firstName: this.get('currentContact.firstName'),
      lastName: this.get('currentContact.lastName'),
      contacttype: 1
    });
    this.get('store').commit(); 
},

Updated jsFiddle is here: http://jsfiddle.net/GYbeT/21/

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

Comments

2

I have found some problems in your sample:

1 - Your model doesn't have a fname and lname property. Just firstName and lastName.

2 - Your modal is bound to currentContact and when you show the modal, you don't suply the currentContact.

Just create a empty contact and leave the bindings set the values.

showmodal: function(){
    this.set('currentContact', App.Person.createRecord());
    $('#modal').modal();
}

The 1 and 2, is why your data is blank.

3 - You forget to rollback the transaction if the user exit from modal, without saving.

I have done this using:

$(document).delegate('.modal', 'hidden', function() { 
    controller.get('currentContact.transaction').rollback();
}); 

Here is the full result http://jsfiddle.net/marciojunior/GYbeT/

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.