CK编辑器第2次验证 [英] CK Editor validates 2nd time

查看:156
本文介绍了CK编辑器第2次验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个CKEditors在我的HTML(我的意思,说多个ckeditors)。



也使用验证插件检查CKEditor是否为空,如果空显示错误。



验证完美,但验证第二次,因为它应该验证第一次本身。





我创建了jsfiddle:小提琴



验证码:



HTML

 < form action =method =postid =frmEditor> 

< p>
< label for =editor1>
编辑器1:
< / label>
< textarea class =ckeditorcols =80id =editor1name =editor1rows =10>< / textarea>
< / p>
< p>

< / p>

< p>
< label for =editor1>
编辑器2:
< / label>
< textarea class =ckeditorcols =80id =editor2name =editor2rows =10>< / textarea>
< / p>
< p>
< input type =submitvalue =Submit>
< / p>

< / form>

脚本

  $(document).ready(function(){
//在keyup上验证注册表单并提交
$(#frmEditor)。validate({
ignore: ],
debug:false,
rules:{
editor1:{
required:true
},
editor2:{
必需: true
}
},
消息:{
editor1:{
要求:请输入
},
editor2:{
必需:请输入
}
},
submitHandler:function(form){
form.submit();
}
});
});

如果你能帮助我,我会非常感谢。

解决方案

我尝试了下面的解决方案,它工作。

 < textarea name =txtDesc<?php echo $ i;?> id =txtDesc<?php echo $ i;?> class =ckeditorrows =5cols =17><?php echo $ txtDesc?>< / textarea> 
< script>
CKEDITOR.replace(txtDesc<?php echo $ i;?>);
CKEDITOR.add
//CKEDITOR.replace('txtDesc0');
< / script>

如果只有一个ckEditor

  for(instance in CKEDITOR.instances){

CKEDITOR.instances [instance] .on(instanceReady,function(){

// set keyup event
this.document.on(keyup,function(){CKEDITOR.instances [instance] .updateElement();});
//并粘贴事件
this.document.on(paste,function(){CKEDITOR.instances [instance] .updateElement();});

});
}

如果有超过1个ckEditor >

  CKEDITOR.instances [txtDesc0]。on(instanceReady,function(){
this.document.on keyup,function(){CKEDITOR.instances [txtDesc0]。updateElement();});
this.document.on(paste,function(){CKEDITOR.instances [txtDesc0] .updateElement();});
this.document.on(cut,function(){CKEDITOR.instances [txtDesc0]。updateElement();});
});

CKEDITOR.instances [txtDesc1]。on(instanceReady,function(){
this.document.on(keyup,function(){CKEDITOR.instances [ txtDesc1]。updateElement();});
this.document.on(paste,function(){CKEDITOR.instances [txtDesc1]。updateElement();});
.document.on(cut,function(){CKEDITOR.instances [txtDesc1]。updateElement();});
});


I have 2 CKEditors in my HTML (i mean , say multiple ckeditors).

Also I am using Validate plugin for checking if CKEditor is empty,if empty show error.

Validation works perfectly , but it validates 2nd time ,where as it should validate 1st time itself.

I have Checked all the Questions,answers here ,But None helped .

I created jsfiddle : Fiddle

Code for validate :

HTML

<form action="" method="post" id="frmEditor">

    <p>
        <label for="editor1">
            Editor 1:
        </label>
        <textarea class="ckeditor" cols="80" id="editor1" name="editor1" rows="10"></textarea>
    </p>
    <p>

    </p>

    <p>
        <label for="editor1">
            Editor 2:
        </label>
        <textarea class="ckeditor" cols="80" id="editor2" name="editor2" rows="10"></textarea>
    </p>
    <p>
        <input type="submit" value="Submit">
    </p>

</form>

Script

$(document).ready(function(){   
// validate signup form on keyup and submit
    $("#frmEditor").validate({
        ignore: [],
        debug: false,
        rules: {
            editor1:{
                required: true
            },
            editor2:{
                required: true
            }           
        },
        messages: {         
            editor1: {
                required: "Please enter"
            },
            editor2: {
                required: "Please enter"
            }           
        },
        submitHandler: function(form) {
            form.submit();
        }       
    });
});

I would be thankful if you can help me.

解决方案

I tried following solution and it worked .

        <textarea name="txtDesc<?php echo $i;?>" id="txtDesc<?php echo $i;?>" class="ckeditor" rows="5" cols="17" ><?php echo $txtDesc?></textarea>
        <script>
         CKEDITOR.replace("txtDesc<?php echo $i;?>");
         CKEDITOR.add       
            //CKEDITOR.replace('txtDesc0'); 
        </script>   

If there is only 1 ckEditor

for (instance in CKEDITOR.instances) {

    CKEDITOR.instances[instance].on("instanceReady", function () {

        //set keyup event
        this.document.on("keyup", function () { CKEDITOR.instances[instance].updateElement(); });
        //and paste event
        this.document.on("paste", function () { CKEDITOR.instances[instance].updateElement(); });

    });
}                                   

If there are more than 1 ckEditor(in my case 2)

CKEDITOR.instances["txtDesc0"].on("instanceReady", function () {
this.document.on("keyup", function () { CKEDITOR.instances["txtDesc0"].updateElement(); });
this.document.on("paste", function () { CKEDITOR.instances["txtDesc0"].updateElement(); });
this.document.on("cut", function () { CKEDITOR.instances["txtDesc0"].updateElement(); });
});

CKEDITOR.instances["txtDesc1"].on("instanceReady", function () {
this.document.on("keyup", function () { CKEDITOR.instances["txtDesc1"].updateElement(); });
this.document.on("paste", function () { CKEDITOR.instances["txtDesc1"].updateElement(); });
this.document.on("cut", function () { CKEDITOR.instances["txtDesc1"].updateElement(); });
});             

这篇关于CK编辑器第2次验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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