保存x-editiable

时间:2015-04-28 12:45:05

标签: javascript jquery x-editable

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

我想出了这个Fiddle,但第一个解决方案有点冗长,第二个解决方案(基于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;
        }
    }
});

1 个答案:

答案 0 :(得分:2)

x-editable documentation表示您需要在输入无效时返回字符串。我已使用工作样本更新了您的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";
        }
    }
});
相关问题