cancel
Showing results for 
Search instead for 
Did you mean: 
Subscribe

Hello,

I am trying to create a function to delete data after user press delete button on MessageBox of confirmation.

I know that it will work following code;

MessageBox.confirm(
 "Delete data?", {
 title: "Delete confirmation",
 onClose: function(oAction) {
   switch(oAction) {
     case "OK":
       /* do delete operation */
       break;
     default:
       break;
 }
);

But, I want to know how to separate the callback function from the code of MessageBox as below, becasue this application needs post-processes after deletion so that the code will be longer, I think it should not be included in the code of calling MessageBox.

~~~~~~~
MessageBox.show(
 "Delete data?", {
 title: "Delete confirmation",
 onClose: ".afterDeleteConfirmation"
);

~~~~~~

afterDeleteConfirmation: function(oAction) {
   switch(oAction) {
     case "OK":
       /* do delete operation */
       break;
     default:
       break;
 }
0 Likes
View Entire Topic
former_member540067
Active Participant

You can create a separate function and call it from the callback. Use the reference of this but you need to assign it to another variable outside the messagebox function.

~~~~~~~

var that=this;
MessageBox.show(
 "Delete data?", {
 title: "Delete confirmation",
 onClose: function(oAction){
     that.afterDeleteConfirmation(oAction);
     }
);

~~~~~~

afterDeleteConfirmation: function(oAction) {
   switch(oAction) {
     case "OK":
       /* do delete operation */
       break;
     default:
       break;
 }

Regards

Anmol

Joseph_BERTHE1
Active Contributor

Hello,

You can simplify it like this :

MessageBox.show(
 "Delete data?", {
 title: "Delete confirmation",
 onClose: this.afterDeleteConfirmation.bind(this)
);

Regards,

Joseph

Former Member
0 Likes

Your answer also works and I learnt how to call function by using "that". Thank you.