Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a button to a dialog box dynamically

Is there any way to add a button to a dialog box in jquery ui dynamically.

I tried using: $(this).add("button");

like image 504
Kut Avatar asked Nov 29 '10 14:11

Kut


2 Answers

This is answered right on the jQuery UI page for dialog... http://jqueryui.com/demos/dialog/ (click "Options" tab, then the link for "Buttons")

"Get or set the buttons option, after init"...

$( ".selector" ).dialog( "option", "buttons", { 
 "Ok": function() { $(this).dialog("close"); } 
} );

Just add the appropriate selector (whatever element you're using as the dialog), and you should be good to go.

like image 56
charliegriefer Avatar answered Sep 20 '22 12:09

charliegriefer


Sometimes you want to add the buttons later too.

var mydialog = ... result of jqueryui .dialog()
var buttons = mydialog.dialog("option", "buttons"); // getter
$.extend(buttons, { foo: function () { alert('foo'); } });
mydialog.dialog("option", "buttons", buttons); // setter
like image 30
JJS Avatar answered Sep 21 '22 12:09

JJS