views:

370

answers:

5

Hi,

If i want to create a JQuery UI dialog, i use something like:

var settings = {autoOpen:false, draggable:false, and so on...};

var dialog = $("#container").dialog(settings);

But now i want to know how i can i retrieve dialog settings as shown above, something like

dialog.getSettings();

I need it because i have an application that uses many dialogs with a default behavior. Something like

function doAfterSubmit(dialogSettings) {
    // some code
}

var dialogSettings = {
    user:{
        add:{
            title:"Add user",
            buttons:{
                "Add":function() {
                    var settings = $(this).getSettings(); // The answer goes here

                    // AJAX to send some content

                    doAfterSubmit(settings);
                }
            },
            otherProperties
        },
        remove:{
            title:"Remove user",
            buttons:{
                "Remove":function() {
                    var settings = $(this).getSettings(); // The answer goes here

                    // AJAX to send some content

                    doAfterSubmit(settings);
                }
            },
            otherProperties
        },
        removeAll:{
            title:"Remove all user",
            buttons:{
                "Remove all":function() {
                    var settings = $(this).getSettings(); // The answer goes here

                    // AJAX to send some content

                    doAfterSubmit(settings);
                }
            },
            otherProperties
        }
    }    
}

After seeing JQuery UI dialog source, i have noticed a property called defaults which contains all properties of the dialog component. But how can i get this defaults property ?

regards,

A: 
// Get or set any dialog option. If no value is specified, will act as a getter.
.dialog( 'option' , optionName , [value] );
cballou
A: 

Try dialog.options, although I'm curious to know why you want to look at them (which may change the answer).

Jonathan Feinberg
+2  A: 
dialog.dialog('option', 'name_of_option');

That should return the dialog option for that one.

What you could do is keep the list of names and loop through them to rebuild the settings array. Why exactly do you need all the options returned?

Daniel
Good suggestion, UPvote
Arthur Ronald F D Garcia
+1  A: 

Using your code example, you should do something like this...

var optionValue = dialog.dialog('option' , optionName);

Where optionName is something like 'height', 'position', 'resizable' etc.

It's all in the JQuery UI documentation

EDIT: Having seen the comments that you added to other answers, it sounds like you need a helper method that provides the functionality you need (It probably should have been provided as part of the main plugin)

Something that simply calls .dialog('option', xxxx) for every option and places them all in an associative array. I can't help thinking, though, that even with this array at your disposal, you'll then be back to pulling a single option out of the array, instead of puling it directly from the dialog. Or are you planning on using the array to create a second dialog from?

belugabob
Yes, i want to retrieve the dialog settings to create a second dialog.
Arthur Ronald F D Garcia
If you created the original dialog, then you should already have a copy of 'settings', to use when creating the second (third, fourth) dialog - or am I missing something?
belugabob
A: 

As Daniel pointed out, you can loop through the variable 'settings' eachwise, and construct your own object for getSettings() to act upon.