SweetAlert 输入验证

Rah*_*war 1 javascript jquery

我希望当用户尝试提交一个空表单时警报不会消失,而是应该在同一个警报中显示一些错误。我尝试执行 swal.showInputError("some error") 但它给出了一个错误,它不是有效的功能。我尝试查看文档,但找不到任何...

这是我的代码-

    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{


            }

});
Run Code Online (Sandbox Code Playgroud)

Gla*_*mos 5

您可以使用此功能:

inputValidator: (value) => {
    return !value && 'You need to write something!'
  }
Run Code Online (Sandbox Code Playgroud)

这将验证用户是否正在写入值。

  • 甜蜜警报 2 - 7.15.1 (2认同)