与ckeditor集成的textarea的jQuery验证 [英] jquery validation of textarea integrated with ckeditor

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

问题描述

我有一个文本区域

<td><textarea id="event-body" name="body">
<p class="error"></p>

与CKEDITOR整合

That is integrated with CKEDITOR

CKEDITOR.replace("event-body")

插件。代码如下

$('#event').validate({
    rules:{
        name:{
            required: true
        },  
    },
    messages:{
        body:{
            required: "event body is required"
        }
    },
    errorPlacement: function(error, element){
        $(element).each(function (){
            $(this).parent('td').find('p.error').html(error);
        })
    });

代码工作正常,但当我输入到 textarea 元素,我仍然得到错误消息,直到我单击它两次。即我必须提交我的页面两次,以便我不会错误消息,即使 textarea 不为空。

The code works just fine but when I type into my textarea element, I still get the error message until I click it twice. i.e. I have to submit my page twice so that I don't error message even if textarea is not empty.

没有办法顺利验证它(无需点击两次)。

Isn't there a way to validate it smoothly(without having to click it twice).

推荐答案

查看此处

基本上你需要调用

CKEDITOR.instances.editor1.updateElement();

editor1 使用您的textarea的名称。

Just replace editor1 with the name of your textarea.

然后调用

$(myformelement).validate();

EDIT

$("#my-form-submit-button").click(function(e){
     e.preventDefault();
     CKEDITOR.instances.event-body.updateElement();
     $('#event').validate({
          ...options as above..
     });o
})

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

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