ckeditor数据未通过jQuery验证验证 [英] ckeditor data not being validated by jQuery validation

查看:175
本文介绍了ckeditor数据未通过jQuery验证验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多关于这个问题的问题,但我不能让这个工作在我的生活。我尝试过几种解决方案,包括 this 第二个答案在这里,我不能得到必需消息出现。当ckeditor字段为空时,表单仍然提交。



我查看了文档这里,并能够将编辑器的内容传递到警报,但没有足够的经验,知道如何将此与验证插件集成。我花了这么多时间在这 - 任何人都可以帮助?



这是我当前的代码,我创建了一个小提琴: http:// jsfiddle.net/BmZ93/1/

  $('#add-job')。validate({
规则:{
editor1:{
required:function()
{
CKEDITOR.instances.editor1.updateElement();
}
}
jobid:必需,
Jobid:必需,
Job_id: Required,
editor1:Required
}
});


解决方案

>

http://jsfiddle.net/rohanppatil/BmZ93/8/

  $(document).ready(function(){
$('#add-job')。 validate({
ignore:[],
rules:{
editor1:{
required:function()
{
CKEDITOR.instances.editor1。 updateElement();
}
}
},
消息:{
Job_Title:Required,
Job_Location:Required,
jobid:Required,
Job_Cat:Required,
editor1:Required
},
/ *如果需要,请使用下面的部分* /
errorPlacement:function(error,element)
{
if(element.attr(name)==editor1)
{
error.insertBefore textarea#editor1);
} else {
error.insertBefore(element);
}
}
});
});希望这将工作我在JSFIDDLE工作正常测试这


I know there are loads of questions out there about this but I can't get this to work for the life of me. I have tried several solutions including this, the second answer here and this, and I can't get the "required" message to appear. The form still submits when the ckeditor field is empty.

I looked at the documentation here and am able to pass the contents of the editor to an alert but am not experienced enough to know how to integrate this with the validation plugin. I've spent so much time on this - can anyone please help?

Here is my current code, and I created a 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"
                } 
        });

解决方案

Here it is update your code with this

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);
                    }
                }
            });
});

Hope this will work I tested this in JSFIDDLE working fine

这篇关于ckeditor数据未通过jQuery验证验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆