Mohamed Emad Hegab
Mohamed Emad Hegab

Reputation: 2675

jquery Ui Dialog can't fadeout twice

i have a strange problem with jquery i have this div that shows messages for ajaxified actions and i want the message to go away when after 5 seconds .. it works for the first time.. but when i trigger the action again in the same page the dialog appears but and never get fade out no matter what unless i close it by press the X button .. the code is

    jQuery( "#dialog" ).dialog({
    open: function(event, ui) {
setTimeout(function(){
    jQuery("#dialog").dialog("close");
}, 5000);

    },
hide: "fadeOut"
});

and it's included in a jsp page that include in all ajax pages..what is the problem??

Upvotes: 1

Views: 534

Answers (3)

Jason Geiger
Jason Geiger

Reputation: 2112

Add autoOpen:false and open manually each time. This code is simple and should work fine. Replace "ELEMENTID" with the ID of your dialog.

$("#ELEMENTID").dialog({
    autoOpen: false
});
$("#ELEMENTID").dialog("open");

Upvotes: 0

Andreas
Andreas

Reputation: 21881

Take a look at this blog entry from nemikor (as stated on the jquery-dialog page)

Every time you call that code snippet, jquery tries to create a new dialog-instance with id dialog. Create that dialog on start up with the autoOpen option set to false and display the dialog by calling dialog('open')

example on jsfiddle

Upvotes: 2

Mohamed Emad Hegab
Mohamed Emad Hegab

Reputation: 2675

I got it anyway.. i should remove the dialog div everytime it closed looks dirty work but in get a good result

Upvotes: 1

Related Questions