gpt4 book ai didi

javascript - SubmitHandler jQuery 验证提交空 CkEditor

转载 作者:行者123 更新时间:2023-11-28 08:08:46 31 4
gpt4 key购买 nike

嗨,我用过jQuery Validation在提交之前验证我的表单。

我以这种方式拦截提交处理程序:

  <script type="text/javascript">
<![CDATA[

$(function() {
$( "#_${sec_form}_id" ).validate({
errorElement: "span",
submitHandler: function(form) {
form.submit();
}
});

$.validator.addMethod(
"validator",
function(value, element, regexp) {
if(value != null && value.trim()!=""){
var re = new RegExp(regexp);
return re.test(value);
}else{
return true;
}
},
"Inserire un valore coerente."
);
});
]]>
</script>

在该表单中,我有一些 CKeditor 字段,但是当我提交表单时,我会丢失对 ckeditor 字段的所有编辑。

如果我删除提交处理程序,一切正常。

你对此有什么想法吗?

谢谢

最佳答案

您可以在提交之前将 CKEditor 字段的值复制到实际的文本区域,以便忽略您的错误。

CKEDITOR.on('instanceReady', function () {
$.each(CKEDITOR.instances, function (instance) {
CKEDITOR.instances[instance].document.on("keyup", CK_jQ);
CKEDITOR.instances[instance].document.on("paste", CK_jQ);
CKEDITOR.instances[instance].document.on("keypress", CK_jQ);
CKEDITOR.instances[instance].document.on("blur", CK_jQ);
CKEDITOR.instances[instance].document.on("change", CK_jQ);
});
});

function CK_jQ() {
for (instance in CKEDITOR.instances) {
CKEDITOR.instances[instance].updateElement();
}
}

要尝试这个,请检查这个 fiddle :http://jsfiddle.net/ryleyb/QcJ57/

有关更多信息,请检查此问题:Jquery validation not working with ckeditor

关于javascript - SubmitHandler jQuery 验证提交空 CkEditor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24511867/

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