sweetalert icon indicating copy to clipboard operation
sweetalert copied to clipboard

Feature Suggestion: Multiple Content Objects

Open darrena092 opened this issue 6 years ago • 4 comments

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.

darrena092 avatar Oct 03 '18 09:10 darrena092

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

t4t5 avatar Oct 03 '18 10:10 t4t5

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?

jjbutnotreally avatar Nov 22 '18 12:11 jjbutnotreally

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

Defcon0 avatar Aug 19 '19 09:08 Defcon0

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 });

bthiban avatar Sep 06 '19 03:09 bthiban