大佬教程收集整理的这篇文章主要介绍了使用 jquery 表单验证时,CKeditor 实例 updateElement() 无法完美运行,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个包含三个 texarea 的表单,名称和 ID 分别为 description
、@H_128_3@mission 和 vision
。三个textareas都有CKeditor。
我需要验证三个 textarea 是否有内容。为了使文本区域更新为 CKeditor 的内容,建议使用以下代码。
for(var instancename in CKEDITOR.instances)
{
CKEDITOR.instances[instancename].updateElement();
}
我将上述代码集成到我的 jquery 表单验证功能中,如下所示:-
这是我的 jquery 验证函数
$("#editPostForm").valIDate({
ignore: "",rules: {
description: {
required : true,minlength : 3
},mission: {
required : true,vision: {
required : true,minlength : 3
}
},messages: {
description: {
required : "Please enter description of about us",minlength : "About us should be atleast 3 characters"
},mission: {
required : "Please enter description of mission",minlength : "Mission should be atleast 3 characters"
},vision: {
required : "Please enter description of vision",minlength : "Vision should be atleast 3 characters"
}
},errorPlacement: function (error,element) {
if($(element).prop('type') == 'textarea')
{
if($(element).prop('name') == 'description')
{
error.insertAfter($('#cke_desc'));
}
else if ($(element).prop('name') == 'mission')
{
error.insertAfter($('#cke_mission'));
}
else if ($(element).prop('name') == 'vision')
{
error.insertAfter($('#cke_vision'));
}
else
{
error.insertAfter($(element));
}
}
},submitHandler : function(form){
for(var instancename in CKEDITOR.instances)
{
CKEDITOR.instances[instancename].updateElement();
}
form.submit();
}
});
这似乎工作得很慢。例如,如果我从某处复制内容并粘贴到编辑器中,然后单击提交按钮,尽管编辑器中有内容,但我会收到验证错误。但是当我第二次立即点击按钮时,表单被提交。
考虑另一种情况。我再次在编辑模式下访问表单,看到数据(之前保存的)显示在编辑器中。我做了一个 ctrl + A 来选择编辑器的整个内容并删除内容。当我点击提交按钮时,表单被提交,因为编辑器尚未更新内容已被删除且当前为空的文本区域。
但是,假设我第一次访问编辑器并单击提交按钮而没有写任何内容,验证错误仍然显示错误消息。
我想知道为什么 updateElement() 需要这么长时间才能工作?
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的使用 jquery 表单验证时,CKeditor 实例 updateElement() 无法完美运行全部内容,希望文章能够帮你解决使用 jquery 表单验证时,CKeditor 实例 updateElement() 无法完美运行所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。