t4t5 / sweetalert

A beautiful replacement for JavaScript's "alert"
https://sweetalert.js.org
MIT License
22.4k stars 2.84k forks source link

Default input value attribute is not handled properly #921

Open quartertone opened 4 years ago

quartertone commented 4 years ago

(Related issues: https://github.com/t4t5/sweetalert/issues/809 , https://github.com/t4t5/sweetalert/issues/893 )

This seems to be an old promblem, but I think is quite important. This bug makes SweetAlert useless as a replacement for the Window.prompt() method.

Also note that this problem seems to occur even with the official example: Try the second example under https://sweetalert.js.org/guides/#using-dom-nodes-as-content

Example code:

document.getElementById("btn").onclick = function() {
 swal("Test default value", {
   buttons: {
    cancel: true,
    ok: {
     value: "Button value"
    }
   },
   content: {
    element: "input",
    attributes: {
     value: "Default value"
    }
   }
  })
  .then((result) => {
   console.log(result);
  });
}

Expected behavior.

What happens: