Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add multiple buttons in Jquery UI dialog box?

I would like to have more than one button. I tried to copy code between brackets but doesnt work.Ideas?

buttons: {

"Close": function() {
 $(this).dialog("close");

}
like image 973
Vonder Avatar asked Mar 25 '10 00:03

Vonder


2 Answers

To add to this, the button array method is useful to know about as it exposes more functionality per button, such as adding icons and other per-button properties. The points to note being the added square brackets around the set of buttons turning it into an array of buttons, and the extra curly braces around each button object.

$("#mydialog").dialog({
  buttons: [{
    text: 'Confirm',
    icons: {
        primary: "ui-icon-check"
    },
    click: function() {
       //do something
       $(this).dialog('close');
    }},{
    text: 'Cancel',
    icons: {
        primary: "ui-icon-cancel"
    },
    click: function() {
       $(this).dialog('close');
    }
  }]
});
like image 84
jgibbs Avatar answered Nov 13 '22 22:11

jgibbs


Create them using this format, 'button text': function() { } with a comma inbetween, like this:

$("#mydialog").dialog({
  buttons: {
    'Confirm': function() {
       //do something
       $(this).dialog('close');
    },
    'Cancel': function() {
       $(this).dialog('close');
    }
  }
});
like image 35
Nick Craver Avatar answered Nov 13 '22 22:11

Nick Craver