What I have is when an edit button is clicked the values in two input fields create a new row and the old row is dropped.Below is the code i used but what i want is that the original row is updated and not deleted. Live Example of how using the code below works.
editBtn.onclick = function () {
alert("Edit Btn");
alert(name.value + " " + Lname.value);
contact.save(null, {
success: function (contact) {
contact.set("FirstName", name.value);
contact.set("LastName", Lname.value);
contact.save();
object.destroy({
success: function (myObject) {
alert("destroy");
location.reload();
},
error: function (myObject, error) {
alert("Error: " + error.code + " " + error.message);
}
});
}
});
}
just to clarify I want to update the rows not create a new one while deleting the old one.
EDIT: Link to above question asked in parse forums.
EDIT: more information added in link as a reply to a comment.
EDIT: I added this code which is actually editing the first name ("NewFname") but It wont update the last name ("NewLname").
editBtn.onclick = function () {
var query = new Parse.Query(Contact);
query.equalTo("LastName", NewLname.value);
query.first({
success: function (Contact) {
Contact.save(null, {
success: function (contact) {
contact.set('FirstName', NewFname.value);
contact.set('LastName', NewLname.value);
contact.save();
location.reload();
}
});
}
});
}
Where I have query.equalTo("LastName", NewLname.value), I tried to put in objectId i.e. (query.equalTo("objectId"); but that didn't work for me.
any ideas?
Thomas
I managed to get it updating with this code.
editBtn.onclick = function () {
var query = new Parse.Query(Contact);
query.equalTo("objectId", object.id);
query.first({
success: function (Contact) {
Contact.save(null, {
success: function (contact) {
contact.set("FirstName", NewFname.value);
contact.set("LastName", NewLname.value);
contact.save();
location.reload();
}
});
}
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With