patel
patel

Reputation: 635

durandal.js confirmation box not able to return yes or no

i would like to add comfirmationbox in durandal.js

i wrote following to code , but it is not returning Yes or NO

define(['services/logger', 'durandal/plugins/router', 'durandal/app'], function (logger, router, app) {

if (app.showMessage('Are you sure you want to delete :' + titlename + '?', 'Delete Confirmation', ['Yes', 'No'])) {
                DeleteAchievement(self, obj.Soid)
            }

Upvotes: 2

Views: 1404

Answers (2)

Mirko Lugano
Mirko Lugano

Reputation: 985

From what it says here app.showMessage() returns a promise, that means you have to write your if statement when the promise has been resolved, that is (in this case) when the user clicks yes or no and the dialog is closed. Your code (which worked for me) would then be like

app.showMessage('Are you sure you want to delete :' + titlename + '?', 'Delete Confirmation', ['Yes', 'No']).then(function (dialogResult) {
            if(dialogResult == 'Yes'){
                 //this is called if user clicked yes
            }else{
                 //this is called if user clicked no
            }
        });

Upvotes: 1

Julián Yuste
Julián Yuste

Reputation: 1472

the showMessage method returns a promise, so your code should look like:

app.showMessage('Are you sure you want to delete :' + titlename + '?', 'Delete Confirmation', ['Yes', 'No']).then(function(dialogResult){
    if(dialogResult === "Yes"){
        //Your code
    }
});

You can get more info here: http://durandaljs.com/documentation/Showing-Message-Boxes-And-Modals/

Upvotes: 5

Related Questions