0
votes

I am using dialog box from link jQuery Confirm

$.dialog({
    title: '',
    content:'test' ,
    animation: 'scale',
    boxWidth: '50%',
    useBootstrap : false
});

Now I want to close it on button click. There are three custom button on which I perform different functionality on each and then want to close dialog box. So on each button I call onclik function in which some task is done. and then I want to close dialog box

<button onclick="update_details(some parameters);">Close</button>

function update_details(parameters)
{
   // task here depend on parameters  
   // Close dialog box here
}

This button is inside dialog box. I tried possible solutions I found here but not working. I hide it using class. but then I can not reopen it. also tried to call close on $dialog

Update :

$.ajax({
  type:'POST',
  cache:false,
  async:false,
  url: 'url here',
  data:{ },
  success:function(resp){   
    if(resp!='')
    {
        for(var i =0; i < somelenghth from resp; i++)
        {
            str = str + '<button onclick="update_details(parameters);" class="btn btn-default">name</button><br><br>';
        }           

        $.dialog({
              title: '',
              content:str ,
              animation: 'scale',
              boxWidth: '50%',
              useBootstrap : false
          });
    }
  }
});
1
Please show us which "possible solutions" you tried and why they failed.Constantin Groß
The docs explicitly state for .dialog(): " removes buttons and explicitly shows the closeIcon (×) " - are you sure you don't want to use .confirm() instead?Constantin Groß
Connum : Updated questionhrishi
I still don't see where you try to implement the close button functionality.Constantin Groß
The link to jQuery Confirm you added contains the answer you're looking for.Mina

1 Answers

0
votes

If you put the content of your dialog inside tags and assign an ID to it then you will be able to reference it from external functions. Also, you may want to add the close event to destroy the dialog every time is closed.

var closedFunction = function() {
    $(#dialogDiv).dialog( "destroy" );
};

$(#dialogDiv).dialog({
    title: '',
    close: closedFunction,
    content:'test' ,
    animation: 'scale',
    boxWidth: '50%',
    useBootstrap : false
});

So, having the dialog content referenced by ID you can include this in your button code to close it.

<button onclick="update_details(some parameters);">Close</button>

function update_details(parameters)
{
    $(#dialogDiv).dialog( "close" );
    // task here depend on parameters  
}

Hope this helps you