Customize the cancel code button of the X-editable (AngularJS)

Mils picture Mils · Jan 24, 2014 · Viewed 6.9k times · Source

Is that possible when the user add a new row and by clicking on the cancel button(without put any data), the row will be deleted. Otherwise how can I change the cancel button code, because this one use the default xeditable code of angularJS.(Or maybe how can I call the delete function if the row is empty?)

This is the EXAMPLE.

HTML for the cancel button:

      <button type="button" ng-disabled="rowform.$waiting" ng-click="rowform.$cancel()" class="btn btn-default">
        cancel
      </button>

Answer

michael picture michael · Jan 24, 2014

You may call your own function. To achieve this you should change your html like this:

<button type="button" ng-disabled="rowform.$waiting" 

        ng-click="cancelAdvice(rowform, $index)" 

        class="btn btn-default">
        cancel
</button>

As you can see there is a new function with the form and the current index as parameter. In your controller you have to define this function:

$scope.cancelAdvice = function(rowform, index){
   console.log(rowform, index);
   $scope.removeUser(index);
   rowform.$cancel();
}

Now you can do your own stuff and call the form $cancel if you are done.