簡體   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