views:

836

answers:

1

Hello all,

This is an annoyance that I've tolerated for too long, and finally decided to pursue an answer. I am showing a modal jQuery dialog box in my web app, but the animation to show it doesn't occur in the right order. I'm setting a click event (using jQuery) to a link on a page, and when the user clicks it, it creates a new Dialog, with autoOpen set to true. Cancel from the dialog destroys it so that the user can open it again on the next click.

No matter what animation I use (currently using "blind"), it seems like the whole page dims first, then opens the dialog box (still dimmed), and once the dialog box has completely opened, it undims it. Just not happening in the right order. Has anyone else seen this, or know why this might be happening? Code I'm using to create dialog is below:

function setDialogWindows($dialogDiv, $leftList, $rightList, leftArray, rightArray, $htmlItemList) {

    $dialogDiv.dialog({
     autoOpen: true,
     modal: true,
     show: 'blind',
     hide: 'blind',
     width: 600,
     resizable: false,
     buttons: {
      Cancel: function() {
       resetDialog($leftList, $rightList);
       $(this).dialog('destroy');
      },
      'Save': function() {

       if (saveDialog($leftList, $rightList, leftArray, rightArray, $htmlItemList)) {
        showHideItemList("show");
       }
       else
        showHideItemList("hide");

       $(this).dialog('destroy');
      }
     }
    });
}

Any help would be appreciated. Thanks.

+1  A: 

I was able to get this to display correctly within IE and FireFox where the page was dimmed and the dialog animation completed correctly (non-dimmed). Do you have any other jQuery script that's acting on that <div> tag?

EDIT: I was just able to recreate this issue. It would seem that it's an issue with the initial displaying of the dialog box combined with an animation. In your case, because your constantly creating/destroying the dialog this would appear every time. Here's something you might want to try:

function setupDialog($dialogDiv) {
    // set autoOpen: false
    // within Cancel and Save use .dialog('close')
}

// Define the dialog boxes:
setupDialog($('#dialog1')); 
setupDialog($('#dialog2')); 
setupDialog($('#dialog3')); 

// Show the dialog on button clicks:
$('#button1').click(function() {
    $('#dialog1').dialog('open');
});
$('#button2').click(function() {
    $('#dialog2').dialog('open');
});
$('#button3').click(function() {
    $('#dialog3').dialog('open');
});
CAbbott
@CAbbott, I don't do anything specific with that div anywhere else in my code. However, I use a generic function called setDialog that I use to construct three separate (very similar) dialog boxes, and pass in the div I want to use to construct. Which div I pass in is based on click events attached to different links on the page. Could this have something to do with it?
Mega Matt
@Matt - Possibly :). 2 things to keep in mind: 1) animations like 'blind' are asynch so if you're doing anything else with that div tag it can mess-up the display. 2) any previous things you've set on that div tag are still in effect (like a toggle). Is it only effects that make it act like that? do removing 'hide:' and 'show:' makes it work correctly?
CAbbott
@CAbbott, Well it all happens so fast, but I'm pretty sure when I removed the hide/show effects, it all happens at the same time. I.e. the background dims and the dialog box appears at the same moment. This is better than what I had, but I would certainly prefer (from a user experience perspective) an animation. If I were to leave it without an entry or exit animation, I would at least perfer that the background dim prior to the dialog box appearing, but now I'm just being greedy :). Interesting insight in your previous edit.
Mega Matt
@CAbbott, Well I changed my implementation to the way you suggested, by creating them upfront, and then only closing and showing them. However, the animation bug remains. Just a little more info...
Mega Matt
@Matt - Yeah, I had the bug happen on the first display of the dialog box, but not on subsequent displays. It seems to me to be a bug with the jQueryUI.
CAbbott