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.
$(function() {
// using textbox value instead of variable
$("#dialog").dialog({
width: 400,
buttons: [
{ text: $("#buttonText0").val(), click: function() { $(this).dialog("close"); } },
{ text: $("#buttonText1").val(), click: function() { $(this).dialog("close"); } }
]
});
$("#updateButtonText").on("click", function() {
var $buttons = $("#dialog").dialog("widget").find(".ui-dialog-buttonpane button");
console.log($buttons.get());
$buttons.eq(0).button("option", "label", $("#buttonText0").val());
$buttons.eq(1).button("option", "label", $("#buttonText1").val());
// few more things that you can do with button widget
$buttons.eq(0).button("option", "icons", { primary: "ui-icon-check" });
$buttons.eq(1).button("disable");
$("#dialog").dialog("open");
});
});
@import url("https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.min.css");
Proceed?