gpt4 book ai didi

javascript - X-editable:验证失败时关闭编辑区域

转载 作者:行者123 更新时间:2023-11-30 06:27:48 24 4
gpt4 key购买 nike

我有什么:

某个页面有多个评论。每个用户都可以修改他所有的评论。

$.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();

});
});

关于javascript - X-editable:验证失败时关闭编辑区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19975207/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com