保存前添加确认提示 x-editable

Add confirm prompt before saving x-editiable

如何在保存 x-editiable (http://vitalets.github.io/x-editable/) 之前添加确认提示?如果对确认提示的响应是否定的,则 x-editable 对话框应该关闭并且不应更新值。

我想出了这个 Fiddle, but the first solution is a little verbose and the second solution (based on x-editable prompt before updating the value) 不起作用。

Test 1<a href="javascript:void(0)" id="name1"></a>
<br>
Test 2<a href="javascript:void(0)" id="name2"></a>

$('#name1').on('shown', function(e, editable) {
    var button=$('input.myClass').parent().next().find('button.editable-submit');
    console.log(button,e,editable,this);
    button.click(function(){
        if(!confirm("Are you sure you wish to proceed?")){
            editable.hide();
            return false;
        }
    });
});

$('#name1').editable({inputclass:'myClass'});

$('#name2').editable({
    validate: function (x) {
        console.log(x,this);
        if(!confirm("Are you sure you wish to proceed?")){
            //Doesn't work
            return false;
        }
    }
});

x-editable documentation says you need to return a string when the input is invalid. I have updated your fiddle 带有工作样本。

$('#name2').editable({
    validate: function (x) {
        console.log(x,this);
        if(!confirm("Are you sure you wish to proceed?")){
            // Hide the editable
            $('#name2').editable('toggle');
            return "invalid";
        }
    }
});