Sweetalert 验证空控件

Sweetalert Validation null control

我正在尝试检查 sweetalert 中的空字符。你能帮我吗? 当您输入的文本 ID 为空时,我想收到提醒

 $(function () {
            $("#btnCreate").click(function (e) {
                e.preventDefault();
               
                
                swal({
                    title: "Ok ?",
                    text: "text",
                    type: "info",
                    showCancelButton: true,
                    cancelButtonClass: 'btn-secondary waves-effect',
                    confirmButtonClass: 'btn-success waves-effect waves-light',
                    confirmButtonText: "Yes",
                    closeOnConfirm: false,

                })
                    .then(val => {
                        if (!val) throw null;
                        swal("Saved!", "Your record has been saved.", "success")
                            .then((confirm) => {

                                $("#CreateForm").submit();
                            })
                    });
            });
  <form id="CreateForm">
  <input type="text" id="text" />
  <input type="submit" value="Submit" id="btnCreate"/>
</form>

您可以决定在第一个弹出窗口(确认操作弹出窗口)之前或之后执行此操作

案例 1:“在第一次弹出之前:

 $(function () {
            $("#btnCreate").click(function (e) {
                e.preventDefault();

               if($('#text').val() === ""){
                   return swal({
                     title:"Field cannot be empty",
                     type:"danger"
                  })
               }
                
                swal({
                    title: "Ok ?",
                    text: "text",
                    type: "info",
                    showCancelButton: true,
                    cancelButtonClass: 'btn-secondary waves-effect',
                    confirmButtonClass: 'btn-success waves-effect waves-light',
                    confirmButtonText: "Yes",
                    closeOnConfirm: false,

                })
                    .then(val => {
                        if (!val) return null;
                        swal("Saved!", "Your record has been saved.", "success")
                            .then((confirm) => {

                                $("#CreateForm").submit();
                            })
                    });
            });
})

案例 2:"AFTER FIRST POPUP"


     $(function () {
                $("#btnCreate").click(function (e) {
                    e.preventDefault();

                    swal({
                        title: "Ok ?",
                        text: "text",
                        type: "info",
                        showCancelButton: true,
                        cancelButtonClass: 'btn-secondary waves-effect',
                        confirmButtonClass: 'btn-success waves-effect waves-light',
                        confirmButtonText: "Yes",
                        closeOnConfirm: false,

                    })
                        .then(val => {
                            if (!val) return null;
                           if($('#text').val() === ""){
                                   return swal({
                                   title:"Field cannot be empty",
                                   type:"danger"
                               })
                           }

                            swal("Saved!", "Your record has been saved.", "success")
                                .then((confirm) => {

                                    $("#CreateForm").submit();
                                })
                        });
                });
})