t4t5 / sweetalert

A beautiful replacement for JavaScript's "alert"
https://sweetalert.js.org
MIT License
22.39k stars 2.84k forks source link

Feature Suggestion: Multiple Content Objects #864

Open darrena092 opened 5 years ago

darrena092 commented 5 years ago

It might make sense to allow multiple content objects to be specified as an array.

At present, content must be specified in the following way:

swal({
    content: {
        element: "p",
        attributes: {
            innerText: "Test element"
        }
    }
});

It would be nice to be able to do this:

swal({
    content: [
        {
            element: "p",
            attributes: {
                innerText: "Enter your password below"
            }
        },
        {
            element: "input",
            attributes: {
                placeholder: "Password"
            }
        }
    ]
});

Happy to submit a PR, just wanted to get a feel for what the opinion on this suggestion is before doing anything.

t4t5 commented 5 years ago

Why not have a single div element and add the p and input tags as children to it?

jjbutnotreally commented 5 years ago

It would be nice if this was supported, I often find a lot of my use cases that could be solved by swal don't work because of the "hacky" nature of the content attribute.

I would love to see content supporting an array of objects (as above) which then return the value of each content element (assuming it's some form of input) as part of the promise response when an action is triggered.

@t4t5 do you have any plans to implement this at all?

Defcon0 commented 4 years ago

Same here. Would love to have this feature in a library such great besides that.

bthiban commented 4 years ago

We can do a work around this issue.

const wrapper = document.createElement('div'); wrapper.innerHTML = YOUR_DYNAMIC_HTML;

swal({ title: 'Test Title', text: 'Test Text', content: wrapper });