Can anyone tell me how can i use a variable for button text in jQuery UI dialog? I want to make a dynamic button name.
Yes completely possible with inline behaviour:
function ConfirmDialog() {
var yesButtonName = "Yes";
var noButtonName = "No";
this.showMessage = function(message, callback, argument) {
var $dialog = $('')
.html(message)
.dialog({
modal: true,
closeOnEscape: true,
buttons: [
{
text:yesButtonName,
click: function() {
if (callback && typeof(callback) === "function") {
if (argument == 'undefined') {
callback();
} else {
callback(argument);
}
} else {
$(this).dialog("close");
}
}
},
{
text:noButtonName,
click: function() {
$(this).dialog("close");
}
}
]
});
$dialog.dialog("open");
};
this.setYesButtonName = function(name) {
yesButtonName = name;
return this;
};
this.setNoButtonName = function(name) {
noButtonName = name;
return this;
};
}
Create Object of ConfirmDialog class.
this.CONFIRM_DIALOG = new ConfirmDialog();
Call method on any event, let's say onclick()
OK_DIALOG.setYesButtonName('Wana Marry').showMessage('Worst Idea!!');
Job Done!!