Jurudocs
Jurudocs

Reputation: 9165

Jquery UI Modal Dialog not working

I have a lot of trouble to find a way to make jquery ui modal dialog work..the modal dialog just returns false...

a fiddle ou can see here http://jsfiddle.net/fVrFj/6/

    function modal_delete_pics(){
            $(function(){
              $( "#dialog:ui-dialog" ).dialog( "destroy" );

              $( "#dialog-confirm" ).dialog({
                resizable: false,
                height:140,
                modal: true,
                buttons: {
                    "delete": function() {
                       $( this ).dialog( "close" );

                                     return true;
                },
                    "cancel": function() {
                        $( this ).dialog( "close" );
                        return false;

                }
            }

        });
    });
};
    $('#clickme').click(function(){
        if(modal_delete_pics()==true){
           $('body').append('<div>deleted</div>');  
           }
          else{                   
             $('body').append('<div>canceled</div>');
              }
});

Thanks a lot!

Upvotes: 1

Views: 6907

Answers (1)

jk.
jk.

Reputation: 14435

You have got a function ($( "#dialog-confirm" ).dialog) within a function ($(function()) within another function (function modal_delete_pics()).

And, the return value from the innermost function ($( "#dialog-confirm" ).dialog) is not bubbling up.

You could try a simpler approach:

$("#dialog-confirm").dialog({
        resizable: false,
        height: 140,
        modal: true,
        autoOpen: false,      
        buttons: {
            "delete": function() {
                //put your image delete code here
                $('body').append('<div>deleted</div>');
                $(this).dialog("close");
            },
            "cancel": function() {
                $('body').append('<div>canceled</div>');
                 $(this).dialog("close");
            }
        }
});

$('#clickme').click(function() {
    $("#dialog-confirm").dialog("open");
});​

Fiddle: http://jsfiddle.net/fVrFj/10/

Upvotes: 4

Related Questions