Sweetalert: How and where would I modify to add multiple buttons on the success modal

Created on 12 Jan 2016  ·  4Comments  ·  Source: t4t5/sweetalert

Hey
On the success modal, I was wondering if there ws a way i could add few buttons which would tell the user something like

'Hey, job a done successfully"
'Now you can do one of the below"
"Option1-link" "Option2-link" "Option3-link"

I now this is not what the plugin is for but if i had to tweak this plugin to start accepting a jsn like {text:'', link:''} a collection of it and render buttons accordingly... where would i begin with ?

Most helpful comment

I might be a little late, but I hope this can help.

https://github.com/andrew-mestas/swalExtend/tree/master

All 4 comments

AFAIK, you can't. The two button system is hardcoded throughout the script. It would require a significant amount of changes to make it work. What you can do is use the html option to add your own buttons in the body of the modal.

I got this to work, some javascript i had to right, might not be the correct way to do this, but worked for me. Sharing it here

if (buttons) {
            var className = ".sweet-alert";
            var container = "<div class='sw-btn-container'><div class='buttons'></div></div>";
            $(className).after("h2").append(container);
            var buttonDiv = ".sweet-alert .buttons";
            _.each(buttons, function (item) {
                if (item.url) {
                    $(buttonDiv).append("<a class='confirm' href='" + item.url + "'>" + item.text + "</a>");
                } else if (item.onclick) {
                    $(buttonDiv).append("<a class='confirm' onclick='" + item.onclick + "'>" + item.text + "</a>");
                }
            });
        }

I might be a little late, but I hope this can help.

https://github.com/andrew-mestas/swalExtend/tree/master

That plugin its just what I needed, thanks for the info :D

Was this page helpful?
0 / 5 - 0 ratings

Related issues

girishbr picture girishbr  ·  5Comments

daftspunk picture daftspunk  ·  4Comments

rafatux picture rafatux  ·  5Comments

adiwithadidas picture adiwithadidas  ·  4Comments

krishnamraju picture krishnamraju  ·  3Comments