views:

133

answers:

2

I am trying to close an open dialog at the end of a function call and also use my current button element to close the dialog. Here is the code that opens the dialog. It is being called dynamically using the 'rel' attribute of the '.modal_btn'. It opens just as expected:

    modalDialog = function(dialogId){
        $(dialogId).dialog({
            modal: true,
            draggable: false,
            resizable: false,
            width: 'auto',
            open: function() { $(".ui-dialog-titlebar-close").hide(); }
        });
    }

    $('.modal_btn').live('click', function(){
        var dialogId = $(this).attr('rel');
        modalDialog(dialogId);
    });

Now after the dialog is open I would like to use my current HTML elements for buttons: a Cancel and Save button. The save button executes the ajax call and after the ajax call is complete I would like to close the dialog. Also, I would like to be able to close the open dialog just by clicking the Cancel button. I just can't seem to grasp this simple functionality...any ideas?

+2  A: 

$(dialogId).dialog('close');?

Edit in response to comment:

Well, how about this then. In your modalDialog function, apply a class to the dialog itself: $(dialogId).addClass('currently-open-dialog').

Then your close click function can do $('.currently-open-dialog').removeClass('currently-open-dialog').dialog('close');

Stuart
yea that was my first thought, however dialogId is not defined by the clicking of the close dialog button...lets say the class is '.close_dialog_btn'...thanks for the fast response!
ThePixelProdigy
Edited with a possible solution to that.
Stuart
brilliant! love the creativity Stuart. Thank you!
ThePixelProdigy
Hope it works for you :) If it does, you get to give me my first 'correct answer' checkmark!
Stuart
done buddy! works great!
ThePixelProdigy
A: 

couple of ways to put text on the button: standard cancel and literal. Same basic action method however:

'Yes, Save and Exit': function()
            {
                callMyAjaxFuction();
                $(this).dialog('close');
                            },
            Cancel: function()
            {
                $(this).dialog('close');
            }
Mark Schultheiss