Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use a jQueryUI Dialog for confirmation?

I'm trying to use the jQueryUI Dialog to get user confirmation before a database update, but I'm battling to see how I can tell what the user's choice on the dialog is, as all in samples I can find, both buttons just close the dialog, with no persistence of the chosen button. E.g. from the jQueryUI sample and docs:

            buttons: {
                'Deactivate the campaign': function () {
                    $(this).dialog('close');
                },
                Cancel: function () {
                    $(this).dialog("close");
                }
            }
like image 590
ProfK Avatar asked Oct 26 '22 20:10

ProfK


1 Answers

Your calling the same function ( $(this).dialog('close'); ) for both buttons. You need to do somehting more than just close the dialog. You can update a hidden span to pass which button was clicked or just call the DB update from there.

buttons: {
        'Deactivate the campaign': function () {
            //pass the value using a hidden span
            $('#myHiddenControl').val('True');

            //or just call the db update
            $.ajax({/* db call code ommited*/});

            $(this).dialog('close');
        },
        Cancel: function () {
            //pass the value using a hidden span
            $('#myHiddenControl').val('False');
            $(this).dialog("close");
        }
}
like image 130
ctrlShiftBryan Avatar answered Nov 15 '22 06:11

ctrlShiftBryan