[Solved] Confirmation Alert not working when called from action sheet


#1

Hi ! i am using Action sheet to show a few options to user, at handler of one button i called a confirmation alert, confirmation alert shows up but its buttons do not work.
I have tried to call that confirmation alert from separate button and it works fine there.
Is it some sort of bug in ionic 2 ?

here is code for confirmation alert:

showConfirm() {
    let confirm = this.alertCtrl.create({
      title: 'Use this lightsaber?',
      message: 'Do you agree to use this lightsaber to do good across the intergalactic galaxy?',
      buttons: [
        {
          text: 'Disagree',
          handler: () => {
            console.log('Disagree clicked');            
          }
        },
        {
          text: 'Agree',
          handler: () => {
            console.log('Agree clicked');
          }
        }
      ]
    });
    confirm.present();
  }

this is for action sheet:

presentActionSheet() {
   let actionSheet = this.actionSheetCtrl.create({
     title: 'Modify your album',
     buttons: [
       {
         text: 'Destructive',
         role: 'destructive',
         handler: () => {
           console.log('Destructive clicked');
           **this.showConfirm();**
         }
       },
       {
         text: 'Archive',
         handler: () => {
           console.log('Archive clicked');
         }
       },
       {
         text: 'Cancel',
         role: 'cancel',
         handler: () => {
           console.log('Cancel clicked');
         }
       }
     ]
   });

   actionSheet.present();
 }

Any help will be appreciated. Thanks in advance :slight_smile:


Why Call Alert is not working properly
#2

Finally this problem was solved by using promise, confirmation alert will be shown when action sheet animation is completed.

actionSheet.dismiss().then(()=>{
  this.showConfirm();
}); 

Found this solution from a problem posted in forum. here is the link from where i found solution.


#3

Had the same issue and it fixed it. Thank you.


#4

i am glad it helped you. :slight_smile:


#5

Very good, just complementing the answer,
If you use the Promise in ActionShettButton do so:

    text: 'Delete',
    icon: 'trash',
    role: 'destructive',
    handler: () => {
      act.onDidDismiss(() => {
        this.showConfirmDelete(item);
      });
    }