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

标签 javascript jquery x-editable

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

我想出了这个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;
        }
    }
});

最佳答案

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";
        }
    }
});

关于javascript - 保存前添加确认提示 x-editable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29919904/

相关文章:

javascript - 由于双击文本链接而导致重复的数据库条目

javascript - 如何设置 cookie 的多个值并将它们全部显示在另一个页面上?

javascript - 面板内的 jQuery Accordion 对齐

javascript 只重新加载一次

javascript - 具有可编辑元素的表单在 angular-x-editable 示例代码中应具有 `editable-form` 属性

javascript - fatal error : CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory error

javascript - 使用 KineticJS 在舞台上动态添加圆圈

javascript - 如何阻止谷歌验证码执行?

javascript - jQuery 在最后一个框中显示按钮

jquery - 无法使用 X-Editable/jQuery、Chrome 读取 JSON