3

I need to change the text of my dialog button but I have 3 dialog buttons with me and I only need to change one of them.

i have this jquery code:

$("dialog").dialog({
height: 600,
width: 1000,
modal: true,
resizable: false,
buttons: {
     "Upload": function() {
           alert("Upload");
      }
     "Edit": function() {
           $('#dialog').dialog("option", "buttons",[
                    {
                        text: "Save",
                        click: function () {
                            alert("Save");
                        } 
                    }
                ]);
      }
     "Delete": function() {
           alert("Delete");
      }
}

This solution change the Edit Button to Save button but it removes the Upload and Delete button. I may add the Upload and Delete again inside the Edit function but I think it doesn't look good that way.

Please let help me have a better solution with this.

Thank you.

SyntaxError
  • 3,717
  • 6
  • 30
  • 31

3 Answers3

2

try this

 buttons:
            [
              {
                  text: "Your name"

              }
            ]

or

$('selector').dialog({
    buttons: {
        OK: function() {
            alert(1);
        }
    },
    dialogClass: 'my-dialog'
});
$('.my-dialog .ui-button-text:contains(OK)').text('CANCEL');
PSR
  • 39,804
  • 41
  • 111
  • 151
1

You can assign a class to your button when you create it, giving you a nice clean way to reference it.

Here's a working example on jsfiddle and the revised code:

$("#dialog").dialog({
height: 600,
width: 1000,
modal: true,
resizable: false,
        buttons:
            [
              {
                  text: "Upload",
                  click: function() {
                     alert("Upload");
                  }
              },
              {
                  text: "Edit",
                  click: function() {
                    $(".editbutton > .ui-button-text").text("Save"); 
                  },
                  'class': 'editbutton'
              },
                {
                  text: "Delete",
                  click: function() {
                     alert("Delete");
                  }
              }
            ]
    });
Colin Pickard
  • 45,724
  • 13
  • 98
  • 148
0

As Colin points out you can assign a class, id and behaviors to buttons in the declaration of the dialog. In order to locate and change text after the dialog is created use something like:

$('#button-id').click(function(){
    $(this).children('ui-button-text').text("new text");
});