我知道有很多关于此的问题,但我无法让它在我的生活中发挥作用。我尝试了几种解决方案,包括 this , the second answer here和 this ,而且我无法显示“必需”消息。当 ckeditor 字段为空时,表单仍会提交。
我查看了文档 here并且能够将编辑器的内容传递给警报,但我没有足够的经验知道如何将其与验证插件集成。我在这上面花了很多时间-有人可以帮忙吗?
这是我当前的代码,我创建了一个 fiddle :http://jsfiddle.net/BmZ93/1/
$('#add-job').validate({
rules: {
editor1: {
required: function()
{
CKEDITOR.instances.editor1.updateElement();
}
}
},
messages: {
Job_Title: "Required",
Job_Location: "Required",
jobid: "Required",
Job_Cat: "Required",
editor1: "Required"
}
});
最佳答案
这是用这个更新你的代码
http://jsfiddle.net/rohanppatil/BmZ93/8/
$(document).ready(function() {
$('#add-job').validate({
ignore: [],
rules: {
editor1: {
required: function()
{
CKEDITOR.instances.editor1.updateElement();
}
}
},
messages: {
Job_Title: "Required",
Job_Location: "Required",
jobid: "Required",
Job_Cat: "Required",
editor1: "Required"
},
/* use below section if required to place the error*/
errorPlacement: function(error, element)
{
if (element.attr("name") == "editor1")
{
error.insertBefore("textarea#editor1");
} else {
error.insertBefore(element);
}
}
});
});
希望这会起作用我在 JSFIDDLE 中测试过它工作正常
关于javascript - jQuery 验证未验证 ckeditor 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20763216/