0

iam using jQuery ui dialog widget and im now wondering if there is possible to hide/show a button?

My code looks like this atm:

$(document).ready(function() { 
            $( "#dialog" ).dialog({
                open: function(event, ui) { 
                    $(".ui-dialog-titlebar-close").hide(); 
                    $('.CoverBox').toggle(); 
                },
                close: function(event, ui) { 
                    $(".CoverBox").toggle();
                },
                autoOpen: false,
                position: ["top", 20],
                draggable: false,
                closeOnEscape: true,
                width: 400,
                minHeight: 100,
                buttons: [
                {
                    text: "Nej",
                    class: 'btn btn-sm btn-primary pull-right',
                    click: function() {
                        $( this ).dialog( "close" );
                    }
                },
                {
                    text: "Radera Kategorien",
                    class: 'btn btn-sm btn-danger pull-right',
                    click: function() {
                    alert('Fick med ett ID:' + $(this).data('catID'));
                        $( this ).dialog( "close" );
                    }
                },
                {
                    text: "Radera Allt",
                    class: 'btn btn-sm btn-danger pull-right',
                    click: function() {
                        alert('Fick med ett ID:' + $(this).data('catID'));
                        $( this ).dialog( "close" );
                    }
                }
                ]
            });

    // Link to open the dialog
    $( ".dialog-link" ).click(function( event ) {
        $("#dialog").data('catID', $(this).attr('id'));
            $.get("functions/getArticlesCat.php", { catID: $(this).attr('id') })
            .done(function(data) { 
                if (data == 1) {
                    $(".alert-danger").html('Undersökte även denna kategorien, och det visar sig att den innehåller artiklar. Vill du radera allt eller bara kategorien?');
                    $(".alert-danger").show(); 
                    $("#dialog").dialog("open");
                }
                else { 
                    $(".alert-danger").hide();
                    $("#dialog").dialog("open");
                }
            });
        event.preventDefault();
    });
});

The a:link iam clicking on is checking if there is articles in that category you are trying to delete.

And the thing i want to do is: If there is articles in the category show "Radera Allt" if not hide that button..

Is this possible?

Tommy
  • 667
  • 1
  • 10
  • 25
  • 1
    Take a look here http://stackoverflow.com/questions/577548/how-can-i-disable-a-button-in-a-jquery-dialog-from-a-function – Christian Phillips Nov 18 '13 at 12:58
  • @christiandev thanks so much for that link! Helped me through this! – Tommy Nov 18 '13 at 13:01
  • When iam going to send them to the delete page should i use window location then or is there any other possibilities? – Tommy Nov 18 '13 at 13:04
  • @Tommy it might be best to ask a new question.. You'll have a better chance of it being answered. People might not find your comment.. If you want to direct your comment at someone use the `@` sign followed by their name like it I did at the first of this comment. – Trevor Nov 19 '13 at 23:02

0 Answers0