angular-xeditable
angular-xeditable copied to clipboard
onbeforesave still updates scope/view when HTTP request fails
<a href=#" editable-text="item.username" onbeforesave="updateUser($data, item)">{{ item.username }}</a></td>
$scope.updateUser = function(data, item) {
$http({
method: 'POST',
url: API + '/reset/username/' + item.usersid,
data: {
"email": data,
},
headers: {
'Content-Type': 'application/json'
},
})
.then(function(resp) {
toasty.success('Username changed!');
return true;
}).catch(function(error) {
console.log("Error " + error);
toasty.warning({
title: 'Failed!',
msg: 'Something went wrong',
});
return false;
});
};
Am I doing something wrong here? Dev Console shows the HTTP request failing and the console.log triggering but the item.username is still updated in view
You have to return a string value, not a boolean. http://vitalets.github.io/angular-xeditable/#validate-remote
I've looked at that example but don't fully understand. How would I fix my sample code to make that work?
Try return "Something went wrong"
instead of false.