Sampath
Sampath

Reputation: 65988

Keep Save button when there is an Error on saving with Angular Xeditable

I'm using Angular Xeditable api. Could you tell me how to keep Save button when there is an error.Here I'm not using inbuilt input controls of x editable. I'm using hyper link.When user clicks, it shows the popup and so on.That functionality is working fine.I just need to keep that row on edit mode when there is an error.Then user can enter data without pressing Edit button again.Thanks.

Here is the Fiddle

Html

<td>
  <a href="" ng-click="vm.note(user,rowform)">Note</a>
</td>

js

 $scope.saveUser = function(data, id) {
     alert('Error');
     return;
  };

Note : Please don't consider about the hyper link's functionality on the above fiddle.Just a demo.My key requirement is keep the Save button when there is an error.

Upvotes: 1

Views: 164

Answers (1)

Jonas Eriksson
Jonas Eriksson

Reputation: 171

Not super familiar with x-editable, but there is sort of built in error handler. I'll leave it to the documentation to explain it in detail, but returning a string from the onbeforesave function will make x-editable interpret the function as an error and keep the form open. Try this, should achieve what you are looking for!

$scope.saveUser = function(data, id) {
  var error = true;
  if (error) {
    return "Something went wrong."
  } else {
    angular.extend(data, {id: id});
    return $http.post('/saveUser', data);
  }
};

Upvotes: 1

Related Questions