How to write pre filled input in bootbox

510 Views Asked by At

I want bootbox to fill var name into bootbox input on click update button, but it is not doing it. I have also highlighted the same in the code below

$(document).on("click", ".update", function () {
      var button = $(event.relatedTarget); /*Button that triggered the modal*/
      var name = button.data('name');
      modal.find('.bootbox-input-text').val(name); 
      $('.bootbox-form').find('input').val(name); /* Not Working */
      bootbox.prompt({
        title: 'Enter Description',
        placeholder: 'my placeholder',
        
        buttons: {
          confirm: {
            label: 'Submit'
          }
        },
        callback: function (value) {
          value && alert('You have entered: ' + value);
        }
      });
    });
1

There are 1 best solutions below

0
Tieson T. On

As noted in the documentation, you can provide the initial value for a prompt using the value option:

$(document).on('click', '.update', function (e) {
    let button = $(this); /*Button that triggered the modal*/
    let name = button.data('name');
    
    bootbox.prompt({
        title: 'Enter Description',
        placeholder: 'my placeholder',

        value: name, /* this is the option you would use */

        buttons: {
          confirm: {
            label: 'Submit'
          }
        },
        callback: function (value) {
          value && alert('You have entered: ' + value);
        }
    });
});