Slinky
Slinky

Reputation: 5832

Auto Close JQuery UI Dialog

All,

I am trying to set a timeout on my JQuery UI Dialog but have not been able to get it to work. I read several SO posts and the docs on setTimeout() but apparently I am not implementing it correctly.

Below, is the syntax that I am using to set up my timeout, along with the dialog HTML.

Thanks

$.ajax({
        type: "POST",
        url: '/Dashboard/BackgroundCheck',
        data: queryStr,
        datatype: 'json',
        success: function (data) {
         if (data == true) {

            $("#dialog-message").attr('title', 'Success!');
            $(".js-dialog-content").html('Background Check status saved.');
            $("#dialog-message").fadeIn('slow');
            $("#dialog-message").dialog({
               modal: true,
               buttons: {
                 Ok: function () {
                 setTimeout(function() {
                   $(this).dialog("close");
                 },5000);
               }
             }
          });
        }
      }
    });

   }
});

Dialog Box

 <div id="dialog-message" title="" style="display:none">
    <p>
      <span class="ui-icon ui-icon-circle-check" style="float: left; margin: 0 7px 50px 0;"></span>
      <span class="js-dialog-content"></span>
    </p>
  </div>

Upvotes: 0

Views: 2265

Answers (1)

QMaster
QMaster

Reputation: 3904

You should define your dialog parameters and you can use autoOpen or open it manually. please attention to this sample:

$('#dialog-message').dialog({
                        autoOpen: false,
                        resizable: false,
                        show: 'fade',
                        hide: 'fade',
                        height: 240,
                        modal: true,
                        dialogClass: "alert",
                        close: function (event, ui) { /*do somthing you want*/ },                        
                        open: function (event, ui) { setTimeout(function () { $('#dialog-message').dialog("close"); }, 2000) }
                    }).dialog("open");

As you can see i set the timeout in function related to open parameter. Good Luck.

Upvotes: 2

Related Questions