I have an AngularJS application in which I use Xeditable in order to modify table values on the fly. I am using a standard method of editing values without showing any buttons and using the blur attribute in order to submit all my changes rapidly and in-line.
<a href="#" buttons="no" blur="submit">{{ myValue }}</a>
Instead of the confirmation being seen as buttons such as on countless examples, they should be only shown in a dialog upon saving (onblur).
Due to user interaction issues, I would like to show a confirmation dialog when a field is changed and then clicked away from (or when the field exits its edit state). Basically something within the "onbeforesave=" attribute.
This is when the confirmation should pop up informing that user that the value was changed and asking if they want to save it or not.
I know how call a function on the onbeforesave event although since it lies within the controller I don't know how to invoke a confirmation dialog.
The basic Steps are as follows:
- User Clicks on a table cell value
- Cell becomes editable.
- User changes the cell value.
- User clicks away from the cell.
- small confirmation dialog pops up (any user friendly or boostrappy way)
- User confirms or cancels the edit which was made.
- Rinse / Repeat.
Any help is appreciated.
See current fiddle
UPDATE: My latest attempts lead me to implement angular-dailog-service which solved my initial problem above, but I am still unable to resolve the final part of my original question.
Upon clicking onto a cell, changing a value and clicking away, I receive a dialog window (confirmation) which when I hit YES will call my api and save the value - which works. Upon clicking NO however, my value remains changed in the table. This value now needs to be reverted to the previous value. Any help?
- I now use a onshow attribute in order to save my current value of the cell being edited to the scope.
- I use the onbeforesave attribute in order to launch my dialog and perform the Yes/No check.
HTML:
<a href="#" editable-text="myValue" buttons="no" blur="submit" onbeforesave="launchDialog($data)" onshow="onShow($data)" >{{ myValue || 'empty' }}</a>
Controller:
$scope.oldValue = "";
$scope.onShow = function(data){
$scope.oldValue = data;
};
$scope.launchDialog = function(data) {
var dlg = null;
dlg = dialogs.confirm('Value Changed','Do you want to save this change?');
dlg.result.then(function(btn){
//TODO: HIT API AND SAVE VALUE
},function(btn){
//RESET TO OLD VALUE
return "";
});
};
The final piece of the puzzle if figuring out what needs to happen inside my NO click function (where the RESET TO OLD VALUE is).