I don't understand how to add a textarea
type
in sweet
alert.
Similar to type: "input"
$('#saveBtn).click(function(){
swal({
title: "Enter your Name!",
text: "your name:",
type: "input",
showCancelButton: true,
closeOnConfirm: false,
showLoaderOnConfirm: true,
animation: "slide-from-top",
inputPlaceholder: "Write something" },
function(inputValue){
if (inputValue === false)
return false;
if (inputValue === "") {
swal.showInputError("You need to write something!");
return false
}
swal("Nice!", "You wrote: " + inputValue, "success");
});
});
This works fine. But if I use type: "textarea"
instead of type: "input"
This gives error like this:
sweetalert.min.js:1 Uncaught ReferenceError: logStr is not defined
Thanks for help.
You can't use
textarea
as a type since the sweetalert does not support that.Instead you can use html markup with
text
option by settinghtml
option true. But in this way you can't get value inside the textarea as callback variable. For that give an id to the textarea and get value using that.If you are using sweetalert2 or want to use sweetalert2, you can include these:
You can write textarea instead of text
The original SweetAlert plugin is currently unsupported and you probably won't see textarea functionality in it. I created SweetAlert2 which has the
textarea
functionlaity:Textarea example in SweetAlert2 documentation ↗
The transition from SweetAlert to SweetAlert2 is easy, here's the migration guide.