Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On load Set value for sweet alert input

Tags:

sweetalert

In sweet alert 2, How on load to set value in input my sweet alert code

swal({
              title: 'Are you sure?',
              text: "You are going to send emails from the system. Please confirm",                   
              showCancelButton: true,
              input: 'email',

              confirmButtonText: 'Submit',
              confirmButtonColor: '#4aa0f1',
              cancelButtonColor: '#898b8e',
              confirmButtonText: 'Send'
            }).then(function (email) {  
                send_email = email;
                sentHtmtBody_send();
                loadingIcon();
            });
like image 938
Madhuka Dilhan Avatar asked Feb 19 '26 10:02

Madhuka Dilhan


2 Answers

We can add another field

inputValue : 'test value',

after adding it full code we can see it like this

swal({
              title: 'Are you sure?',
              text: "You are going to send emails from the system. Please confirm",                   
              showCancelButton: true,
              input: 'email',
              inputValue: "E.g john",
              confirmButtonText: 'Submit',
              confirmButtonColor: '#4aa0f1',
              cancelButtonColor: '#898b8e',
              confirmButtonText: 'Send'
            }).then(function (email) {  
                send_email = email;
                sentHtmtBody_send();
                loadingIcon();
            });
like image 66
Madhuka Dilhan Avatar answered Feb 21 '26 15:02

Madhuka Dilhan


On sweetalert2 I implement it in this suggested way:

let input = document.createElement("input");
input.value = 'test';
input.type = 'text';
input.className = 'swal-content__input';
swal('Please type:', {
    content: input,
    buttons: ['Cancel', 'Update']
})
.then(() => {
    //
});
like image 35
mcanvar Avatar answered Feb 21 '26 15:02

mcanvar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!