admin管理员组文章数量:1435859
I'm using CKEditor and the jQuery Validation plugin on a project I'm working on.
I've read several very helpful posts on StackOverflow in the last few days which have really helped me in getting CKEditor validated, thanks!
I now want to roll out the code I've written to handle one editor instance to the rest of the project, ideally without duplicating the code or specifying each individual instance by ID. There are many of them over many pages thanks to my customers' specification.
The code I have in the footer of my pages is:
$(document).ready(function() {
CKEDITOR.instances["itissue"].on("instanceReady", function() {
// Set keyup event
this.document.on("keyup", updateValue);
// Set paste event
this.document.on("paste", updateValue);
});
function updateValue() {
CKEDITOR.instances.itissue.updateElement();
$("#itissue").trigger('keyup');
}
});
itissue
is the ID of my instance, the ID is different on each page. I see it needs to be replaced with some type of generic identifier for "all textareas" but this is where my programming and Googling skills have expired.
I would appreciate a nudge in the right direction if anybody has any ideas..
I'm using CKEditor and the jQuery Validation plugin on a project I'm working on.
I've read several very helpful posts on StackOverflow. in the last few days which have really helped me in getting CKEditor validated, thanks!
I now want to roll out the code I've written to handle one editor instance to the rest of the project, ideally without duplicating the code or specifying each individual instance by ID. There are many of them over many pages thanks to my customers' specification.
The code I have in the footer of my pages is:
$(document).ready(function() {
CKEDITOR.instances["itissue"].on("instanceReady", function() {
// Set keyup event
this.document.on("keyup", updateValue);
// Set paste event
this.document.on("paste", updateValue);
});
function updateValue() {
CKEDITOR.instances.itissue.updateElement();
$("#itissue").trigger('keyup');
}
});
itissue
is the ID of my instance, the ID is different on each page. I see it needs to be replaced with some type of generic identifier for "all textareas" but this is where my programming and Googling skills have expired.
I would appreciate a nudge in the right direction if anybody has any ideas..
Share Improve this question edited Dec 6, 2010 at 22:40 Josiah Ruddell 29.8k8 gold badges67 silver badges68 bronze badges asked Dec 6, 2010 at 21:17 Adam BoyleAdam Boyle 611 silver badge4 bronze badges 02 Answers
Reset to default 4Below is the code I used to fix this problem, I hope it es in useful for somebody in the future.
<script type="text/javascript">
$(document).ready(function() {
for(var name in CKEDITOR.instances) {
CKEDITOR.instances[name].on("instanceReady", function() {
// Set keyup event
this.document.on("keyup", updateValue);
// Set paste event
this.document.on("paste", updateValue);
});
function updateValue() {
CKEDITOR.instances[name].updateElement();
$('textarea').trigger('keyup');
}
}
});
</script>
I would validate editors within the submit handler, instead of watching keyup and calling updateElement onkeyup.
To answer your question you need to iterate through the CKEDITOR.instances object.
// validator submit handler
var submitHandle = function(){
for(var name in CKEDITOR.instances){
CKEDITOR.instances[name].updateElement(); // update all instances of ckEditors
}
// proceed with validation check
};
This way you do not need to know the name of an editor instance.
本文标签: javascriptUsing Common Code with CKEditor and jQuery ValidationStack Overflow
版权声明:本文标题:javascript - Using Common Code with CKEditor and jQuery Validation - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745669732a2669500.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论