1

I want to be able to change the title of my modal and the buttons on run time. currently I have this I have actions either approval or Deny

var recButton = actions =='approval' ? 'Approve' : 'Deny';

$("#dialog").dialog(
    {
        modal : true,
        buttons : {
            'update all' : function() {
                // window.location.reload();
                // $( this ).dialog( "close" );
                //do something here
            },
            Cancel : function() {
                $(this).dialog("close");
            }
        }
    }); //dialog
});

I also tried to do this for button

$("#dialog").dialog(
    {
        modal : true,
        buttons : {
            recButton : function() { ...

but in modal it didn't translate well and just said recButton instead of the variable value. Also I need to change title too.

Update: got title working by simply title:

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Asim Zaidi
  • 27,016
  • 49
  • 132
  • 221

1 Answers1

6

Hey Autolycus: try this man: working demo http://jsfiddle.net/C4A9b/10/

Please use firebug to check the element id / class:

$('.ui-dialog-title').html("HULK is awesome"); should do the trick.

Hope it helps :)

code

$(document).ready(function() {
    $('#theLink').click(function(){
                $( "#forgot-dialog" ).dialog( "open" );    
    });

    $( "#forgot-dialog" ).dialog({
            modal: true,
            autoOpen: false,
            height: 255,
            width: 300,
            buttons: {
                "ChangeTitle": function() {

                    alert("Title before cahnge ==> " + $('.ui-dialog-title').html());
                   $('.ui-dialog-title').html("HULK is awesome");
                    // document.forms["forgotform"].submit();
                },
                Cancel: function() {
                    $( this ).dialog( "close" );
                }
            },
    });


});

OR

var formname = "form_name_here";

$("#ui-dialog-title-"+formname).innerHTML = "Hulk is awesome title";

Below Image show before and After.

Image before clicking changetitle button

enter image description here

After clicking change title

enter image description here

Tats_innit
  • 33,991
  • 10
  • 71
  • 77
  • I had change the title already and had the ticket updated before you posted this answer. I was hoping for button text change dynamically – Asim Zaidi Jul 03 '12 at 14:38
  • something like this http://stackoverflow.com/questions/4591642/dynamically-changing-jquery-ui-dialog-box-button-text – Asim Zaidi Jul 03 '12 at 14:40
  • Hiya @Autolycus try this bruv: http://jsfiddle.net/naaT8/1/ when you will click on the button `changetitle` it will change both title and text of the button, this should help. `:)` – Tats_innit Jul 03 '12 at 23:49