繁体   English   中英

X可编辑:验证失败时关闭编辑区域

[英]X-editable: close editing area on validation failure

我有的:

某些页面中有多个评论。 每个用户都可以修改其所有评论。

$.each(comments, function() {
    this.editable({
        type: 'textarea',
        mode: 'inline',
        onblur: 'submit',
        showbuttons: false,
        inputclass: 'edit-comments-text-input',
        validate: function(value) {
            if (!value.trim()) {
                return 'Can not be empty!'; //DON'T CLOSE THE EDITABLE AREA!!!
            }
        },
        success: function(response, newValue){        
            comment.text = newValue.trim();

    });
});

有什么问题:

如果用户输入空字符串,则验证失败。 但是可编辑区域不会关闭,因此用户可以继续并编辑下一个注释,而上一个注释的编辑区域仍处于打开状态。

题:

验证失败时如何关闭编辑文本区域?

我读了一些源代码,然后整理了一下。

重要的一行是:

$('.editable-open').editableContainer('hide', 'cancel');

因此在上面的示例中将是:

$.each(comments, function() {
    this.editable({
        type: 'textarea',
        mode: 'inline',
        onblur: 'submit',
        showbuttons: false,
        inputclass: 'edit-comments-text-input',
        validate: function(value) {
            if (!value.trim()) {
                $('.editable-open').editableContainer('hide', 'cancel');
                return 'Can not be empty!'; //DOES NOW CLOSE THE EDITABLE AREA!!!
            }
        },
        success: function(response, newValue){        
            comment.text = newValue.trim();

    });
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM