Multiple inputs in a Bootbox

kambi picture kambi · May 28, 2013 · Viewed 40.9k times · Source

How can I have 2 inputs instead of just one in Bootstrap's Bootbox?

I need to receive 2 values in a modal dialog.

Answer

haradwaith picture haradwaith · Sep 3, 2013

Actually, there is a simpler way which doesn't require you to modify bootbox code.

The string you pass at the bootbox creation doesn't have to be only text: it can also be html code. That means you can include pretty much everything in the box.

To put a custom form in a bootbox, you can then create it as follow :

bootbox.confirm("<form id='infos' action=''>\
    First name:<input type='text' name='first_name' /><br/>\
    Last name:<input type='text' name='last_name' />\
    </form>", function(result) {
        if(result)
            $('#infos').submit();
});