Skip to content

Commit 95a3459

Browse files
committed
Dialog: Added additional syntax for creating buttons. Fixes #4344 - Dialog: Enhanced Button Option.
1 parent dea2f8a commit 95a3459

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

tests/unit/dialog/dialog_options.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,31 @@ test("buttons", function() {
7171
el.remove();
7272
});
7373

74+
test("buttons - advanced", function() {
75+
expect(5);
76+
77+
el = $("<div></div>").dialog({
78+
buttons: [
79+
{
80+
text: "a button",
81+
"class": "additional-class",
82+
id: "my-button-id",
83+
click: function() {
84+
equals(this, el[0], "correct context");
85+
}
86+
}
87+
]
88+
});
89+
var buttons = dlg().find("button");
90+
equals(buttons.length, 1, "correct number of buttons");
91+
equals(buttons.attr("id"), "my-button-id", "correct id");
92+
equals(buttons.text(), "a button", "correct label");
93+
ok(buttons.hasClass("additional-class"), "additional classes added");
94+
buttons.click();
95+
96+
el.remove();
97+
});
98+
7499
test("closeOnEscape", function() {
75100
el = $('<div></div>').dialog({ closeOnEscape: false });
76101
ok(true, 'closeOnEscape: false');

ui/jquery.ui.dialog.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,15 @@ $.widget("ui.dialog", {
357357
});
358358
}
359359
if (hasButtons) {
360-
$.each(buttons, function(name, fn) {
361-
var button = $('<button type="button"></button>')
362-
.text(name)
363-
.click(function() { fn.apply(self.element[0], arguments); })
360+
$.each(buttons, function(name, props) {
361+
props = $.isFunction( props ) ?
362+
{ click: props, text: name } :
363+
props;
364+
var button = $('<button></button>', props)
365+
.unbind('click')
366+
.click(function() {
367+
props.click.apply(self.element[0], arguments);
368+
})
364369
.appendTo(uiButtonSet);
365370
if ($.fn.button) {
366371
button.button();

0 commit comments

Comments
 (0)