views:

23

answers:

1

This question is really using a jQuery dialog to ask a more generic jQuery question.

I need to, in essence, pass a continuation to a modal jQuery dialog.

I want to define a dialog box once on a page, but when calling dialog('open') on it, I want to arrange for the button functions in the dialog to have a value in scope that they can call back.

Given:

var $dialog = $('<div></div>')
                .html('Is this text correctly segmented?')
                .dialog({
                    autoOpen: false,
                    modal: true,
                    title: 'Correct?',
                    buttons: { "Yes": function() { $(this).dialog("close"); 
                                                 },
                               "No":   function() {  $(this).dialog("close");       
                         }
            });

could it be as simple as declaring some other var, referencing it in the button functions, and setting it before opening?

A: 

What I did is the following:

  1. On your page, add a div element that acts as a drop target
  2. In your method that opens a new dialog, create a new dialog with a random ID and append it to the drop target
  3. Open the dialog programmatically

This will allow you to programmatically generate a new dialog, passing it the title, content, buttons, etc. without having to predefine it explicitly on the page.

SimpleCoder