Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SweetAlert input validation

I want the alert to not disappear when the user is trying to submit an empty form,instead it should show some error in the same alert.I tried doing swal.showInputError("some error") but it gives an error that it is not valid function.I tried looking at the documentation but cannot find any...

Here is my code-

    swal({
     title:"Enter a Username",
     content: {
                element: "input",
                attributes: {
                    placeholder: "Type your username",
                    type: "text"
                     },
             },


    className: "mySwal"
    }).then((username)=>{
            //get the username
            if(username){

            }else{


            }

});
like image 220
Rahul jhawar Avatar asked Dec 06 '25 14:12

Rahul jhawar


1 Answers

You can use this function:

inputValidator: (value) => {
    return !value && 'You need to write something!'
  }

This will validates if the user is writing a value.

like image 144
Glauber Avatar answered Dec 08 '25 02:12

Glauber



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!