angular-xeditable icon indicating copy to clipboard operation
angular-xeditable copied to clipboard

onbeforesave still updates scope/view when HTTP request fails

Open ghost opened this issue 7 years ago • 3 comments

<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

ghost avatar Feb 02 '18 12:02 ghost

You have to return a string value, not a boolean. http://vitalets.github.io/angular-xeditable/#validate-remote

ckosloski avatar Feb 02 '18 13:02 ckosloski

I've looked at that example but don't fully understand. How would I fix my sample code to make that work?

Fossil01 avatar Feb 02 '18 13:02 Fossil01

Try return "Something went wrong" instead of false.

ckosloski avatar Feb 02 '18 14:02 ckosloski