3

I'm trying to add more than one button in my Magento 2 modal. I got it to pop up but I can't seem to get another button to appear. and I adding the second button correctly to the array?

UPDATED CODE!

require([
"jquery",
"Magento_Ui/js/modal/modal"
], function($, modal){
var options = {
    type: 'popup',
    responsive: true,
    innerScroll: true,
    title: "Age verification", //write your popup title 
    buttons: [
        {
            text: $.mage.__('Under 21'),
            class: 'under-21 button',
            click: function () {
                console.log('Do something here......');
                // Do something here........
            }
        },
        {
            text: $.mage.__('21+ Enter'),
            class: 'over-21 button',
            click: function () {
                console.log('Do something here......');
                this.closeModal();
                // Do something here........
            }
        }
    ]
};
    var popupdata = $('<div />').append($('#age-check-model'));
    modal(options, popupdata);
    popupdata.modal('openModal');
});

works great now

3

I adding the second button correctly to the array?

No, you add another property to the options object.

Try with this:

require([
    "jquery",
    "Magento_Ui/js/modal/modal"
], function($, modal){
    var options = {
        type: 'popup',
        responsive: true,
        innerScroll: true,
        title: "Age verification", //write your popup title 
        buttons: [
            {
                text: $.mage.__('Under 21'),
                class: 'under-21 button',
                click: function () {
                    console.log('Do something here......');
                    // Do something here........
                }
            },
            {
                text: $.mage.__('21+ Enter'),
                class: 'over-21 button',
                click: function () {
                    console.log('Do something here......');
                    this.closeModal();
                    // Do something here........
                }
            }
        ]
    };

In the above, we add another object to the buttons array

  • worked great, now look at my updated code I'm trying to check if a cookie is there and if not create one as well as hide and show based on cookie being there or not. but it's not working. any idea why? – gx2g Oct 6 '17 at 2:19
  • now I'm having issue with cookie please help – gx2g Oct 6 '17 at 2:24
  • @gx2g you should make a separate thread for your problem – Vivek Kumar Oct 6 '17 at 5:59
  • sorry figured it out. – gx2g Oct 6 '17 at 17:31
  • @Magecode please, provide more information - any error? Try to add it as a checkout component devdocs.magento.com/guides/v2.2/howdoi/checkout/… – Adrian Szulc Aug 4 '18 at 17:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.