1

当我确认提交值并获得成功警报时,我创建了一个输入框,但我在取消按钮上也获得了成功?

swal({
    title: " Asking price for " + askData[0] + "?",
    text: "If you are sure press OK or edit this text",
    type: "input",
    inputType: "text",
    inputValue: "Hello " + askData[1] + ", I am interested in buying your " + askData[0] + " of Variety :" + askData[3] + ". Please update the Price!",
    showCancelButton: true,
    closeOnConfirm: false,
    showLoaderOnConfirm: true
}, function (inputValue) {
    if (inputValue === "") {
        swal.showInputError("Please write something !");
        return false;
    }
    $.ajax({
        url: urlEnq,
        type: "GET"
    });
    $.ajax({
        url: 'saveUserMessage',
        type: "POST",
        data: {
            fieldUserId: fieldUserId,
            filedUserCompanyId: filedUserCompanyId,
            message: inputValue
        },

    })
        .done(function (data) {
            swal("Done!", "Your message has been successfully sent.", "success");
        })
        .error(function (data) {
            swal.showInputError("Please write something !");
        });
4

1 回答 1

2

当使用SweetAlert时,传递给回调函数的变量的值将是false,而不是''在单击取消时。

我已经更新了您的jsfiddle以显示这一点,请参阅下面的更新代码:

$('button.delete-account').click(function (e) {
    swal({
        title: "Are you sure you want to delete your account?",
        text: "If you are sure, type in your password:",
        type: "input",
        inputType: "password",
        showCancelButton: true,
        closeOnConfirm: false
    }, function (typedPassword) {
        if (typedPassword === false) {
            return;
        }
        if (typedPassword === "") {
            swal.showInputError("You need to type in your password in order to do this!");
            return false;
        }
        $.ajax({
            url: "/api/delete-account",
            data: { password: typedPassword },
            type: "POST"
        }).done(function (data) {
            swal("Deleted!", "Your account has been deleted!", "success");
        }).error(function (data) {
            swal.showInputError("Your password is wrong!");
        });
    });
});
于 2015-12-03T04:55:56.307 回答