我想让ckeditor工作.显然它没有使用textarea所以提交表单不会在编辑器中提交文本.因为我使用了多态关联等.我不能使用onsubmit函数来获取textarea的值(当提交表单时).
所以我发现了这个问题:使用jQuery从CKEditor的iframe中获取内容
有一些非常好的答案.在那里发布的答案使textarea保持最新.这非常好,正是我需要的!不幸的是我无法让它发挥作用.有人知道为什么(例如)这不起作用?
我有一个textarea(rails但它只是转换为普通的textarea):
<%= f.text_area :body, :id => 'ckeditor', :rows => 3 %>
以下是js:
if(CKEDITOR.instances.ckeditor ) {
CKEDITOR.remove(CKEDITOR.instances.ckeditor);
}
CKEDITOR.replace( 'ckeditor',
{
skin : 'kama',
toolbar :[['Styles', 'Format', '-', 'Bold', 'Italic', '-', 'NumberedList', 'BulletedList', 'Link']]});
CKEDITOR.instances["ckeditor"].on("instanceReady", function()
{
//set keyup event
this.document.on("keyup", CK_jQ);
//and paste event
this.document.on("paste", CK_jQ);
}
function CK_jQ()
{
CKEDITOR.instances.ckeditor.updateElement();
}
Run Code Online (Sandbox Code Playgroud)
我在我的萤火虫中得到以下"错误".
missing ) after argument list
[Break on this error] function CK_jQ()\n
我知道那里有很多关于这个的问题,但我不能让这个为我的生活工作.我已经尝试了几个解决方案,包括这个,第二个答案在这里和这个,我无法得到"必需"的消息出现.当ckeditor字段为空时,表单仍然会提交.
我查看了这里的文档,并且能够将编辑器的内容传递给警报,但是我没有足够的经验知道如何将它与验证插件集成.我花了这么多时间在这上面 - 有人可以帮忙吗?
这是我目前的代码,我创建了一个小提琴: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"
}
});
Run Code Online (Sandbox Code Playgroud)