Search code examples
javascriptbootstrap-4bootbox

Set id for bootbox textarea


Below is code to open bootbox with textarea:

bootbox.prompt({
  title: "This is title",
  inputType: 'textarea',
  placeholder: 'Feedback',
  callback: function (result) { console.log(result); }
});

I can see textarea created like below:

<textarea class="bootbox-input bootbox-input-textarea form-control" placeholder="Feedback"></textarea>

I tried to give id like: id: "test_id", but it is giving me an error. Can anyone help please?

I am opening this bootbox on click of one button.


Solution

  • You can add id by jQuery in simple way .

        bootbox.confirm({
          message: 'message',
          buttons: {
           'confirm': {
             title: "This is title",
             inputType: 'textarea',
             placeholder: 'Feedback',
             label: 'OK',
             className:'bootbox-input bootbox-input-textarea form-control'
            }
         },
         callback: function(result) {
           if (result) {
            console.log("OK clicked");
           }
          }
        });
    
        $(".bootbox-input-textarea").attr('id', 'bootbox-confirm-id');
    
    <textarea class="bootbox-input bootbox-input-textarea form-control" placeholder="Feedback"></textarea>
    

    For more information , visit the LINK