Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onbeforesave still updates scope/view when HTTP request fails #719

Open
ghost opened this issue Feb 2, 2018 · 3 comments
Open

onbeforesave still updates scope/view when HTTP request fails #719

ghost opened this issue Feb 2, 2018 · 3 comments

Comments

@ghost
Copy link

ghost commented Feb 2, 2018

<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

@ckosloski
Copy link
Contributor

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

@ghost
Copy link
Author

ghost commented Feb 2, 2018

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

@ckosloski
Copy link
Contributor

Try return "Something went wrong" instead of false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant