7

How do I remove the buttons in a jquery dialog? Per example, I tried re-calling .dialog with the correct new options, but the dialog seems unaffected.

$('.selector').dialog('option', 'buttons', {} ); does not work, and nor does it work if actual new button strings and functions are declared.

Thoughts?

5
  • 1
    Can you post more sample code? Commented Jul 15, 2009 at 17:38
  • jqueryui.com/demos/dialog/#option-buttons Commented Jul 15, 2009 at 19:31
  • As it turns out, this does work, but it'll silently fail if your syntax is dialog({'option',...}); Commented Jul 15, 2009 at 20:21
  • Care to add an answer that notes the correct syntax that will not cause it to silently fail then? I've got that problem now, and the correct answer would be appreciated. Commented May 10, 2010 at 17:48
  • There is no correct syntax. You can't set the buttons as the dialog loads; rather, you have to set a callback function to be called once the dialog is done loading. i.e. var callback = showDialog(); callback(); Commented May 10, 2010 at 20:29

6 Answers 6

13

You are passing new buttons set in a wrong way. Options should be passed as an object.

This will work:

var options = {
    buttons: {}
};
$(selector).dialog('option', options);

No need to destroy and create new dialog.

Of course you can also replace buttons object with a new set of buttons if you wish:

var options = {
    buttons: {
        NewButton: function () {
            $(this).dialog('close');
            // add code here
        }
    }
};
$(selector).dialog('option', options);
Sign up to request clarification or add additional context in comments.

Comments

4

FWIW,

$(".dialog").dialog("option", "buttons", null);

Comments

2

Buttons cannot be added/set while the dialog is loading.

Comments

0

You need to destroy the current one first. Then you can make a new one with the new options you want.

EDIT (to response to comment): I don't know what to tell you. I did the following on my site and WFM.

$('.selector').dialog('destroy');
$('.selector').dialog({ buttons: { "Ok": function() { $(this).dialog("close"); } } });
$('.selector').dialog('open');

You need to return to pre-init state to alter the buttons, which is what destroy does. Maybe I just wasn't clear enough on the steps.

2 Comments

Destroying hides. Of course I can destroy the dialog and build it again, but the jquery ui documentation seems to think you can build buttons post-creation.
editing to respond to your comment. you need to return to pre-init state before you can alter the buttons.
0

The discussion here is better: http://www.nabble.com/jQuery-dialog-add-remove-button-on-the-fly-td22036498s27240.html

Add in the prescribed extensions and you can just use addbutton and removebutton (should switch to camel case naturally :)

Comments

0

Anotherm, maybe the simplest, and very flexible way to do this is via CSS. (what if you'll eventually need them in the future...).

Looks like:

.ui-dialog-titlebar-close{display:none}

If you like to do it only for some dialogs, you may add dialogClass: option while initializing the dialog, and your css will look like (e.g. you've added myDialogClass as dialogClass, so the whole dialog container will be accessible via this class:

.myDialog  .ui-dialog-titlebar-close{display:none}

Good luck in customizing!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.