[英]CKEditor Not Validating JQUERY VALIDATING on first click
I am integrating JQUERY Validation with CKEDITOR. 我正在将JQUERY验证与CKEDITOR集成在一起。
This is my HTML 这是我的HTML
<div class="clearfix"></div>
<div class="col-md-12">
<div class="form-group">
<label class="control-label col-md-2">Text<span class="required">*</span></label>
<div class="col-md-8">
<textarea name="text" id="editor1" class="form-control ckeditor" style="height:100px;"><?= $results[0]['text']; ?></textarea>
<span class="help-block"></span>
</div>
</div>
</div>
And this is my Footer 这是我的页脚
<script src="<?= site_url('theme/black/assets/plugins/ckeditor/ckeditor.js') ?>" type="text/javascript"></script>
<script src="<?= site_url('theme/black/assets/plugins/ckeditor/styles.js') ?>" type="text/javascript"></script>
<script>
CKEDITOR.replace('editor');
</script>
And this is my code for Jquery Validation 这是我的Jquery验证代码
<script>
$(document).ready(function () {
$('#edit_banner').validate({
errorElement: 'span',
errorClass: 'error',
focusInvalid: false,
ignore: "",
rules: {
title: {
required: true
},
text: {
required: true
},
sort: {
required: true
},
show_on_dashboard: {
required: true
}
}
});
});
</script>
But the issue is that CKEDITOR is checked on 2nd click. 但是问题是在第二次单击时选中了CKEDITOR。 Not on first.
不首先。 I searched allot and found this
我搜索了分配,发现了这个
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(); });
});
}
But I don't know where to put it? 但是我不知道放在哪里? Can any1 help?
可以帮忙吗?
UPDATE UPDATE
I made changes and put the code inside script tag but it is still not working
<script>
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();
});
});
}
$(document).ready(function () {
$('#edit_banner').validate({
errorElement: 'span',
errorClass: 'error',
focusInvalid: false,
ignore: "",
rules: {
title: {
required: true
},
text: {
required: true
},
sort: {
required: true
},
show_on_dashboard: {
required: true
}
}
});
});
</script>
i too had this problem a long time back..finally i found that there were two event handlers working together in the script I think your problem is in this portion 我也很久以前就遇到过这个问题。.最后,我发现脚本中有两个事件处理程序一起工作,我认为您的问题出在这部分
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(); });
});
}
remove one event handler as per your need..for example like this 根据您的需要删除一个事件处理程序。
for (instance in CKEDITOR.instances) {
//set keyup event
this.document.on("keyup", function () { CKEDITOR.instances[instance].updateElement(); });
//and paste event
this.document.on("paste", function () { CKEDITOR.instances[instance].updateElement(); });
}
hope this may help..:-) 希望这会有所帮助.. :-)
I resolved the issue using this code. 我使用此代码解决了该问题。
<script>
$(document).ready(function () {
jQuery.validator.addMethod("cke_required", function (value, element) {
var idname = $(element).attr('id');
var editor = CKEDITOR.instances[idname];
$(element).val(editor.getData());
return $(element).val().length > 0;
}, "This field is required");
$('#add_banner').validate({
errorElement: 'span',
errorClass: 'error',
focusInvalid: false,
ignore: "",
rules: {
text: {
cke_required: true
},
title: {
required: true
},
sort: {
required: true
},
show_on_dashboard: {
required: true
},
image: {
required: true
}
}
});
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.