Search code examples
javascripttwitter-bootstrapbootbox

Multiple inputs in a Bootbox


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

I need to receive 2 values in a modal dialog.


Solution

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