Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery UI dialog link instead of button

I like to add a button (which is supported by default) and link jQuery UI dialog. How to add a link in jQuery UI dialog? In my case I like to have Save button and a Cancel link. Thanks in advance.

like image 291
Sha Le Avatar asked Oct 14 '25 14:10

Sha Le


2 Answers

You will have to style the button how you want to, but this injects a link and binds the click even to do what you want.

$("#dialog").dialog({
    modal: true,
   open: function(event, ui){
            $('<a />', {
                'class': 'linkClass',
                text: 'Cancel',
                href: '#'
            })
            .appendTo($(".ui-dialog-buttonpane"))
            .click(function(){
                 $(event.target).dialog('close');
            });
    },
    buttons: {
        'Save': function() {
            //save code here.
        }
    }
});​
like image 70
Zacho Avatar answered Oct 17 '25 07:10

Zacho


My approach to this is to wrap the button with a link in order to leverage the jquery ui css without having to style the link.

To access the button you will need to assign it an id in the initial options.

$('#your-selector').dialog({
                        resizable: false,
                        height: 260,
                        closeOnEscape: true,
                        width: 475,
                        modal: true,
                        .....
                        buttons: [
                            {
                                text: "Continue Shopping",
                                id: "continue-d-btn",
                                click: function () { $(this).dialog("close"); }
                            },
                            {
                                text: "Checkout",
                                id: "checkout-d-btn"  // assign an id ! important

                            }
                        ],
                        open: function (event, ui) {
                               // this is where we add an icon and a link
                               $('#checkout-d-btn')
                                .wrap('<a href="[YOUR_LINK]" ></a>');

                        }

                    });
like image 21
LPCmedia Avatar answered Oct 17 '25 07:10

LPCmedia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!